Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Simple Query Help

$
0
0
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. Any help appreciated Thanks
http://img703.imageshack.us/img703/6460/erdversion1.jpg
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.

What I have so far....
Code:

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",
      (model.mod_chg_mile * charter.char_distance)* 1.35 "Charter Charge"
FROM x.customer
LEFT JOIN x.charter ON customer.cus_code = charter.cus_code
JOIN x.aircraft ON charter.ac_number = aircraft.ac_number
JOIN x.model ON aircraft.mod_code = model.mod_code
GROUP BY customer.cus_fname, customer.cus_initial, customer.cus_lname, model.mod_chg_mile, charter.char_distance;

Outputs...
Code:

Customer Name                                # of Flights Charter Charge
-------------------------------------------- ------------ --------------
Leona K. Dunne                                          1        989.82
Myron Orlando                                          1      1677.942
George Williams                                        1      5673.483
George Williams                                        1        2043.09
Leona K. Dunne                                          1      3687.4035
Leona K. Dunne                                          1      3373.812
Myron Orlando                                          1      4993.515
George Williams                                        1        1497.42
Alfred A. Ramas                                        1        2804.49
Myron Orlando                                          1      1323.594
James G. Brown                                          1      5929.4025
James G. Brown                                          1        1015.2
Leona K. Dunne                                          1      2049.435
Kathy W. Smith                                          1      4993.515
Kathy W. Smith                                          1        917.136
James G. Brown                                          1      3166.155
George Williams                                        1        2969.46
Olette K. Smith                                        1      1229.796

 18 rows selected

Before i added the last column, the # of flights were added and if one person didnt fly, they were listed too. Now they are not and need them to be. Any ideas?

Viewing all articles
Browse latest Browse all 13329

Trending Articles