郑州华晶拖欠工资:sql 查询问题。高手进

来源:百度文库 编辑:中科新闻网 时间:2024/05/08 06:52:49
比如 在一个表里。用户名为A的有20条记录, 用户名为B的有18条记录

现在如何查这个表。求出A的某个段的和 和 B某个段的和..
显示只有A和B的记录 的某个字段的和

如果A,B是同一字段
select sum(**) as s from table where username='A' or username='B'
如果A,B是不同字段
select top 1 (select sum(T1.**) from table T1 where T1.username='A')+((select sum(T2.**) from table T2 where T2.username='B') as a from table

select (select sum(T1.**) from table T1 where T1.username='A')+((select sum(T2.**) from table T2 where T2.username='B') as a from table limit 1

没太明白你的意思

看不懂

没看懂,好好说一下

select sum(*) from table where user=a and a>x and a<y
select sum(*) from table where user=b adn b>m and b<n