|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with group by please...important!
Hi,
I have 4 databases: Customer: Customer Name, CityID, Sales City: CityID, CityName, DistrictID District: DistrictID, RegionID Region: RegionID I need to write a SQL query that will show all the customers grouped by region and then district and ordred by sales. Any and all help is greatly appreciated. ![]() |
|
#2
|
|||
|
|||
|
Just to be more specific, I have four tables. The group by function will not work since I am not using an aggregate function. I have the following code but am getting a syntax error:
SELECT C.CUSTOMER_NAME FROM CUSTOMER C INNER JOIN CITY C1 ON C.CITY_ID=C1.CITY_ID INNER JOIN DISTRICT D ON D.SALES_DISTRICT=C1.SALES_DISTRICT INNER JOIN REGION R ON R.SALES_REGION=D.SALES_REGION ORDER BY R.SALES_REGION, D.SALES_DISTRICT; Thanx. |
|
#3
|
|||
|
|||
|
I don't believe that it is grouping that you are after as much as order. Also you don't need to join the region table, that information already exists in the district table
tRY SELECT D.SALES_REGION, D.SALES_DISTRICT, C.SALES, C.CUSTOMER_NAME FROM CUSTOMER C INNER JOIN CITY C1 ON C.CITY_ID=C1.CITY_ID INNER JOIN DISTRICT D ON D.SALES_DISTRICT=C1.SALES_DISTRICT ORDER BY D.SALES_REGION, D.SALES_DISTRICT, C.Sales; S- |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Help with group by please...important! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|