求一个SQL

jx_401 2010-03-31 07:52:40
源数据
Date Money InOrOut Times
2010-03-31 300 0 1
2010-03-31 500 0 1
2010-03-31 200 1 1
2010-03-31 300 1 1
2010-03-30 200 0 2
2010-03-30 200 1 2

目标数据
Date Money1 Money2 Times
2010-03-31 800 500 1
2010-03-30 200 200 2

同样的in或者out加一起,根据times排列
请各位帮忙想想怎么写这个Sql,不胜感激啊~~~~~
...全文
54 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jx_401 2010-03-31
  • 打赏
  • 举报
回复
辛苦了 谢谢
jx_401 2010-03-31
  • 打赏
  • 举报
回复
哦 我加筛选条件了 呵呵 结贴
jx_401 2010-03-31
  • 打赏
  • 举报
回复
不对呀,1那种情况的始终结果是0啊
bancxc 2010-03-31
  • 打赏
  • 举报
回复
select [date],
Money1=Sum(Case InOrOut When 1 then [Money] else 0 end),
Money2=Sum(Case InOrOut When 0 then [Money] else 0 end),
Times
from tb
group by [date],Times
SQL77 2010-03-31
  • 打赏
  • 举报
回复
SELECT 
CONVert(varchar(10),date,120)as date,
sum(case when inorout=1 then Money else 0 end) Money1,
sum(case when inorout=0 then Money else 0 end) Money2,TIMES
from tb group by CONVert(varchar(10),date,120),TIMES
order by 1 DESC
SQL77 2010-03-31
  • 打赏
  • 举报
回复
SELECT 
CONVert(varchar(10),date,120)as date,
sum(case when inorout=1 then Money else 0 end) Money1,
sum(case when inorout=0 then Money else 0 end) Money2
from tb group by CONVert(varchar(10),date,120)
order by 1 DESC
--小F-- 2010-03-31
  • 打赏
  • 举报
回复
select
date,
sum(case InOrOut when 0 then [money] else 0 end) as 'Money1',
sum(case InOrOut when 1 then [money] else 0 end) as 'Money2',
times
from
tb
group by
date,times

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧