ms sql 高手请进? 在线等!!!

jdabin 2011-01-08 04:22:20
select sum(changeMoney) as 变动总额 from dbo.ChangeMoneyInfo
select sum(changeMoney) as 消费总额 from dbo.ChangeMoneyInfo where typeID=1
select sum(changeMoney) as 存款总额 from dbo.ChangeMoneyInfo where typeID=2
select sum(changeMoney) as 取款总额 from dbo.ChangeMoneyInfo where typeID=3


怎么写成一句SQL 语句查出来?
...全文
89 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jdabin 2011-01-08
谢了 你们的比我的灵活, 如果要其他表的数据 你们的要 方便很多
回复
jdabin 2011-01-08

select sum(changeMoney) as 变动总额 ,
sum(case typeID when 1 then changeMoney else 0 end) as 下单,
sum(case typeID when 2 then changeMoney else 0 end) as 撤单,
sum(case typeID when 3 then changeMoney else 0 end) as 存款,
sum(case typeID when 4 then changeMoney else 0 end) as 取款,
sum(case typeID when 5 then changeMoney else 0 end) as 中奖,
sum(case typeID when 6 then changeMoney else 0 end) as 返点
--,sum(select count(addtime) from userInfo where addtime>'2010-1-8' and addtime<'2010-1-8')
from dbo.ChangeMoneyInfo ----这样也可以...
回复
joyhen 2011-01-08
外面套个select就行了啊
回复
feixianxxx 2011-01-08
[Quote=引用 4 楼 llpoo 的回复:]

select
(select sum(changeMoney) as 变动总额 from dbo.ChangeMoneyInfo),
(select sum(changeMoney) as 消费总额 from dbo.ChangeMoneyInfo where typeID=1),
(select sum(changeMoney) as 存款总额 from dbo.ChangeMone……
[/Quote]
...是这样吧..
select
(select sum(changeMoney) as 变动总额 from dbo.ChangeMoneyInfo),
(select sum(changeMoney) as 消费总额 from dbo.ChangeMoneyInfo where typeID=1),
(select sum(changeMoney) as 存款总额 from dbo.ChangeMoneyInfo where typeID=2),
(select sum(changeMoney) as 取款总额 from dbo.ChangeMoneyInfo where typeID=3)
回复
llpoo 2011-01-08
select
(select sum(changeMoney) as 变动总额 from dbo.ChangeMoneyInfo),
(select sum(changeMoney) as 消费总额 from dbo.ChangeMoneyInfo where typeID=1),
(select sum(changeMoney) as 存款总额 from dbo.ChangeMoneyInfo where typeID=2),
(select sum(changeMoney) as 取款总额 from dbo.ChangeMoneyInfo where typeID=3)
from ChangeMoneyInfo
回复
jdabin 2011-01-08
回复
jdabin 2011-01-08
晕了这都很难么?
回复
jdabin 2011-01-08
changeMoney money 类型. 应该不需要其它数据了吧!
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2011-01-08 04:22
社区公告
暂无公告