table: Testid score
1 10
1 20
2 30
2 40
3 50
希望查询结果为:
id score _sum
1 30 5
2 70 5
3 50 5 其中_sum的数值是记录的条数 请教各位高手下这个SQL该怎么写啊,由于数据比较多,希望能够高效。
1 10
1 20
2 30
2 40
3 50
希望查询结果为:
id score _sum
1 30 5
2 70 5
3 50 5 其中_sum的数值是记录的条数 请教各位高手下这个SQL该怎么写啊,由于数据比较多,希望能够高效。
select id,sum(score),count(id) from 表 group by id
用这样的
select id,sum(score),count(id) over() from 表 group by id
试试看,
select id,sum(score),count(*) over()sum from tablename group by id
select id,sum(score),count(id) over() from 表 group by id
在test这个表中 (假设NO为PK)
id score no
1 10 a
1 20 b
2 30 c
2 40 d
3 50 e
over()里面该怎么写才能得到它的总条数的呀?