Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-06-07 : 07:29:09
|
| Johnny writes "I have four tables:Customer: Customer_Name, City_ID, Credit_LimitCity: City_ID, City, Sales_DistrictDistrict: Sales_District, Sales_RegionRegion: Sales_RegionI need to create a query to show all the customer names grouped by sales_region, then sales_district, ordered by credit limit. I have the following query but it is generating a syntax error:SELECT C.CUSTOMER_NAMEFROM CUSTOMER C INNER JOIN CITY C1 ON C.CITY_ID=C1.CITY_IDINNER JOIN DISTRICT D ON D.SALES_DISTRICT=C1.SALES_DISTRICTINNER JOIN REGION R ON R.SALES_REGION=D.SALES_REGIONORDER BY R.SALES_REGION, D.SALES_DISTRICT, C.CREDIT_LIMIT;I don't think I can use the GROUP BY since it requires an aggregate function which I am not using.Thank you for any help you might be able to provide." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-06-07 : 08:01:57
|
| SELECT R.SALES_REGION, D.SALES_DISTRICT, C.CUSTOMER_NAMEFROM CUSTOMER C INNER JOIN CITY C1 ON C.CITY_ID=C1.CITY_IDINNER JOIN DISTRICT D ON D.SALES_DISTRICT=C1.SALES_DISTRICTINNER JOIN REGION R ON R.SALES_REGION=D.SALES_REGIONORDER BY R.SALES_REGION, D.SALES_DISTRICT, C.CREDIT_LIMITCan't see why it gives error - what is the error?==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-06-07 : 08:02:09
|
| You need to put all the fields in your order by within the field list in your select statement for a start...SELECT R.SALES_REGION, D.SALES_DISTRICT, C.CREDIT_LIMIT, C.CUSTOMER_NAMEFROM CUSTOMER C INNER JOIN CITY C1 ON C.CITY_ID=C1.CITY_IDINNER JOIN DISTRICT D ON D.SALES_DISTRICT=C1.SALES_DISTRICTINNER JOIN REGION R ON R.SALES_REGION=D.SALES_REGIONORDER BY R.SALES_REGION, D.SALES_DISTRICT, C.CREDIT_LIMIT |
 |
|
|
|
|
|
|
|