n********6 发帖数: 1511 | 1 Background:
Garage manager wants a summary report for the times of service delivered to the customer per vehicle brand, by
this week, and this year as of today.
Table:
transactionid, Brand, date, ...
1, Ford, 5/1, ...
2, Ford, 5/2, ...
3, Chevy, 7/1, ...
...
m, n, o, 7/20, ...
Expected Output/report format:
Brand, CounterThisWeek(as of today), CouterThisYear(as of today)
Ford, 3, 118
Chevy, 1, 117
...
Toyota, 5, 125
Environment: SQLServer2005
Question:
Can this done by one query? | g***l 发帖数: 18555 | 2 明明是要GROUP BY两次么,为啥用一个QUERY,做样子? | i****a 发帖数: 36252 | 3 try group by brand
and in the query do case date count
to the customer per vehicle brand, by
【在 n********6 的大作中提到】 : Background: : Garage manager wants a summary report for the times of service delivered to the customer per vehicle brand, by : this week, and this year as of today. : Table: : transactionid, Brand, date, ... : 1, Ford, 5/1, ... : 2, Ford, 5/2, ... : 3, Chevy, 7/1, ... : ... : m, n, o, 7/20, ...
| n********6 发帖数: 1511 | 4 Because I need to generate report on web, and look for opportunities to generate one recordset by one query.
【在 g***l 的大作中提到】 : 明明是要GROUP BY两次么,为啥用一个QUERY,做样子?
| n********6 发帖数: 1511 | 5 will try.
【在 i****a 的大作中提到】 : try group by brand : and in the query do case date count : : to the customer per vehicle brand, by
| g***l 发帖数: 18555 | 6 不会做两个QUERY JOIN在一起啊,记得用LEFT JOIN,MONTH的在左边
generate one recordset by one query.
【在 n********6 的大作中提到】 : Because I need to generate report on web, and look for opportunities to generate one recordset by one query.
|
|