求一条Sql语句,关于计数问题的
Sql版本:2008
表格式
id playdate pingname incomesum
1 '2012-05-01' '影院A' 200
2 '2012-05-01' '影院B' 200
3 '2012-05-01' '影院C' 200
4 '2012-05-01' '影院C' 200
5 '2012-05-01' '影院C' 200
6 '2012-05-02' '影院A' 400
7 '2012-05-02' '影院B' 200
8 '2012-05-03' '影院C' 500
9 '2012-05-04' '影院C' 200
10 '2012-05-04' '影院A' 400
11 '2012-05-04' '影院B' 200
12 '2012-05-04' '影院C' 500
13 '2012-05-04' '影院D' 200
要输出的格式
playdate pingname_count incomesum_sum records_count
'2012-05-01' 3 1000 5
'2012-05-02' 2 600 2
'2012-05-03' 1 500 1
'2012-05-04' 4 1500 5
其中pingname_count为 group by pingname的个数,
incomesum_sum 为incomesum 求和
records_count 为playdate中出现的多少笔记录
------解决方案--------------------
SQL code
select playdate,count(distinct pingname) as pingname_count,sum(incomesum) as incomesum_sum,
count(*) as records_count group by playdate