📄 按日期求和.txt
字号:
declare @tab table(rq varchar(10),胜负 char(2))
insert into @tab select '2005-05-09', '胜'
union all select '2005-05-09', '胜'
union all select '2005-05-09', '负'
union all select '2005-05-09' , '负'
union all select '2005-05-10', '胜'
union all select '2005-05-10', '负'
union all select '2005-05-10', '负'
/*解法一*/
select a.rq,a.胜 ,b.负 from
(select distinct(rq) , count(胜负)as 胜
from @tab
where 胜负='胜'
group by rq)a
inner join
(select distinct(rq) , count(胜负)as 负
from @tab
where 胜负='负'
group by rq) b
on a.rq=b.rq
/*解法二*/
select rq,sum(case 胜负 when '胜' then 1 else 0 end)as 胜 ,sum(case 胜负 when '负' then 1 else 0 end)as 负
from @tab group by rq
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -