有一张销售表如下:
user account
001 100.00
002 34.00
003 89.00
005 130.00
006 634.00
007 689.00
......
......现在需要计算一个数据:
找出满足条件 account总和大于等于10000的第一个user。有什么一些简单的方法。
user account
001 100.00
002 34.00
003 89.00
005 130.00
006 634.00
007 689.00
......
......现在需要计算一个数据:
找出满足条件 account总和大于等于10000的第一个user。有什么一些简单的方法。
上面根据user汇总,然后你从里面选出来就是了
大于等于
select sum(account) as total,[user] from xxx group by [user]) v order by v.total asc
select top 1 * from
(
select sum(account) as total,[user] from 你的表名 group by [user] where total>=10000
);
论坛签名======================================================================PCI_E:你好!
截至 2011-10-21 16:54:54 前:
你已发帖 27 个, 未结贴 1 个;
结贴率为: 96.30%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
这样写吧
select top 1 sum(account) as total,[user] from 销售表 group by [user] having SUM(account)>10000
语句不对吧
where条件怎么能在group by语句后面?
select top 1 * from
(
select sum(account) as total,[user] from 你的表名 group by [user] where total>=10000
) a;
论坛签名======================================================================PCI_E:你好!
截至 2011-10-21 16:54:54 前:
你已发帖 27 个, 未结贴 1 个;
结贴率为: 96.30%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx
from
(
select sum(pcount) as total,fileid from #temp_picturedetail
group by fileid
having sum(pcount) >= 100
) a