MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.

Learn More!


Download to Enter
| Contest Rules

Tutorials | Forums

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 4th, 2012, 10:35 PM
a_legs a_legs is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 11 a_legs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 47 sec
Reputation Power: 0
Using Left Outer Join

Hello, thanks for taking the time to read my post. This query was written for me by someone who I cannot get in contact with anymore and I need to alter it. Unfortunately, I do not understand the language well enough. Any help would be appreciated. The query I have totals the number of sessions each client has had in the past 2 months, and subtracts that from the number of sessions each client has paid for to give their total remaining sessions. It lists all clients in the database and how many sessions they have remaining.

SELECT app.demographic_no,app.name,demo.sessions_paid,COALESCE(app.sessions_used,0) AS sessions_used,(demo.sessions_paid – COALESCE(app.sessions_used,0)) AS sessions_remaining FROM (SELECT demographic_no,COUNT(*) AS sessions_used FROM appointment WHERE (appointment_date BETWEEN ‘2012-01-01’ AND ‘2012-02-03’) GROUP BY demographic_no) AS app LEFT OUTER JOIN (SELECT demographic_no,sessions_paid FROM demographic GROUP BY demographic_no) AS demo ON app.demographic_no = demo.demographic_no ORDER BY sessions_remaining desc

What I need is a query that will take ONLY the clients coming TODAY, and subtract all the sessions they have had to date (the day before today) from the sessions they have paid for. Thank you for any input you can offer.

Alexandra

Reply With Quote
  #2  
Old February 5th, 2012, 04:33 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 25,046 r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level)r937 User rank is General 42nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 2 Days 22 h 44 sec
Reputation Power: 3829
Quote:
Originally Posted by a_legs
Hello This query was written for me by someone who I cannot get in contact with anymore
oh, you mean this guy?

sadly, as written, the query you have is broken, and will not return the correct answer for any client that has had 0 sessions used

also, the "curly quotes" used here --
Code:
BETWEEN ‘2012-01-01’ AND ‘2012-02-03’
will not allow the query to be run at all

can you explain?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937 : February 5th, 2012 at 04:35 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Using Left Outer Join


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap