SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Simple query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jptalon
Starting Member

USA
3 Posts

Posted - 10/27/2012 :  13:19:24  Show Profile  Reply with Quote
Hello all,
New here and yes this is classwork. No I'm not looking for just the answer lol. I need to understand this, not just pass the class. Anyways, here is the ERD Im using, and just below it is the output I need. I can do each on its own but not together. Im sure I need the Group by, just haven't gotten it to work. I'm taking classes online and have emailed for help with no response, hence coming here. Any help appreciated Thanks

Create a customer report that lists all customer's names, the number of charters they have booked, and the total cost of all charters. Remember to include all customers, even customer’s that currently do not have any charters booked.

Jptalon
Starting Member

USA
3 Posts

Posted - 10/27/2012 :  14:19:36  Show Profile  Reply with Quote
SELECT TRIM(customer.cus_fname) ||
DECODE(customer.cus_initial,NULL, ' ',
' ' || customer.cus_initial || '. ')
|| TRIM(customer.cus_lname) "Customer Name",
COUNT(charter.char_trip) "# of Flights"
FROM xxx.customer
JOIN xxx.charter ON customer.cus_code = charter.cus_code
GROUP BY customer.cus_fname, customer.cus_initial, customer.cus_lname;

OUTPUTS this....

Customer Name # of Flights
-------------------------------------------- ------------
James G. Brown 3
George Williams 4
Olette K. Smith 1
Kathy W. Smith 2
Leona K. Dunne 4
Alfred A. Ramas 1
Myron Orlando 3

7 rows selected


So I got this part to work right after posting, but it does not list all customers. How could I add that? NULL I believe is what I want....
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/27/2012 :  14:29:57  Show Profile  Reply with Quote
Use LEFT OUTER JOIN instead of INNER JOIN.

BTW, this forum is a Microsoft SQL Server forum, so expertise on other DBMSs are likely to be far and few in between. You will get better and faster responses for other DBMSs at a forum such as dbforums.com
Go to Top of Page

Jptalon
Starting Member

USA
3 Posts

Posted - 10/27/2012 :  14:36:18  Show Profile  Reply with Quote
Thanks. I was just looking back on OUTER JOINS. I will also check the other forum out as I am using SQL developer
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/27/2012 :  21:19:03  Show Profile  Reply with Quote
quote:
Originally posted by Jptalon

Thanks. I was just looking back on OUTER JOINS. I will also check the other forum out as I am using SQL developer



the code looks more like Oracle to me

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000