求个分组统计的sql 表A(userid,money,type)根据类型不同,求每个用户金额,当type=1是加钱,2减少钱 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select userid,sum(case money when type=1 then money when type-2 then -money end) from Agroup by userid select userid,sum(money*(case when [type]=2 then -1 else [type] end)) from tbgroup by userid select userid, sum(case type when 1 then money when 2 then -money else 0 end) as [money]from agroup by userid select sum([money]) from tb group by userid,type select userid,sum(case when type=1 then money when type=2 then -money end) from Agroup by userid select userid, sum(case type when 1 then money when 2 then -money else 0 end) as [money]from agroup by userid SQL2008写一个导出表中数据的脚本 如何实现这样的多列合并效果? 为什么从已经建好的表里导出建表脚本不完全?(报歉只剩20分了) 问题:如何把查到的记录数写到指定的临时表字段里? 如何实现先进先出的出库跟踪入库 存储过程的头10条 如何改表中的一个字段的属性 txt數據導入到sql server中,如果每天導如何處理重復的記錄???? 关于sql server 2000全文检索得问题 ◇选哪种数据库好? SQL动态按月为列进行汇总 请教两条SQL查询语句的执行速度问题。
group by userid
group by userid
userid,
sum(case type when 1 then money when 2 then -money else 0 end) as [money]
from
a
group by
userid
group by userid
userid,
sum(case type when 1 then money when 2 then -money else 0 end) as [money]
from
a
group by
userid