Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Oracle SQL problem  (Read 632 times)

0 Members and 1 Guest are viewing this topic.

reddevilggg

    Topic Starter


    Specialist
  • Thanked: 67
  • Experience: Familiar
  • OS: Windows 7
Oracle SQL problem
« on: April 25, 2012, 03:07:51 PM »

I'm having trouble putting the finishing touch to this SQL statement...........

I have 3 locations (location 2, location 3, location 4)  and each location offers 3 services. I want the query to show each location grouped together with the revenue highest, so that you can see the highest service for each location like so.....

location 2 - Service 2 - £50
location 2 - service 1 - £30
location 2 - service 3 - £10
location 3 - service 3 - £40
location 3 - service 1 - £20
location 3 - service 2 - £10
location 4 - service 2 - £45
location 4 - service 3 - £30
location 4 - service 1 - £20

So far the statement i've got is this -

SELECT location.location_id, location.location_name, service.description, SUM(price) AS REVENUE
FROM location, service, service_line
WHERE service.location_id=location.location_id
AND service.service_id=service_line.service_id
GROUP BY location.location_id, location.location_name, service.description
HAVING SUM (price) > 0
ORDER BY revenue DESC;

Which shows the revenue in descending order but this mixes up the locations.

Can anyone point me in the right direction ?
11 cheers for binary !

Rob Pomeroy



    Prodigy
  • Systems Architect
  • Thanked: 123
    • Me
  • Experience: Expert
  • OS: Other
Re: Oracle SQL problem
« Reply #1 on: April 26, 2012, 07:56:33 AM »
Code: [Select]
ORDER BY location.location_name ASC,  revenue DESC;
Only able to visit the forums sporadically, sorry.

Author of the fantasy thriller, Insensate - available for all ebook readers and iDevices. Find out more >here<. Only 99p/99¢!

reddevilggg

    Topic Starter


    Specialist
  • Thanked: 67
  • Experience: Familiar
  • OS: Windows 7
Re: Oracle SQL problem
« Reply #2 on: April 28, 2012, 12:47:02 PM »

Code: [Select]
ORDER BY location.location_name ASC,  revenue DESC;

ah, of course, Thanks Rob  :)
11 cheers for binary !

Rob Pomeroy



    Prodigy
  • Systems Architect
  • Thanked: 123
    • Me
  • Experience: Expert
  • OS: Other
Re: Oracle SQL problem
« Reply #3 on: April 29, 2012, 10:57:28 AM »
No problem.
Only able to visit the forums sporadically, sorry.

Author of the fantasy thriller, Insensate - available for all ebook readers and iDevices. Find out more >here<. Only 99p/99¢!