胜负sql
Ⅰ sql子查询,分别统计出每支队伍的胜负次数
select a.iwu ,a.胜,b.负 from
(select count(*) 胜, iwu from tabb where shengfu='胜' group by iwu ) a left join
(select count(*) 负, iwu from tabb where shengfu='负' group by iwu ) b on a.iwu=b.iwu
--sql2000调试通过,可以自己用case when改写一下
Ⅱ 用sql语言实现
是用SUM() 函数
SUM 函数返回数值列的总数(总额)。
select 姓名,
Sum(Case when 胜负='胜' then 1 Else 0 End) 胜,
Sum(Case when 胜负='负' then 1 Else 0 End) 负
from 表1 group by 姓名
这个你看下可以不
Ⅲ 关于sql语句查询的问题
如原表有2列,时间和胜负,语句:
select 时间,sum(case when 胜负='胜' then 1 else 0 end) 胜,sum(case when 胜负='负' then 1 else 0 end) 负 from 表
group by 时间
Ⅳ sql查询语句,ABC三只球队各有胜负,要生成下面的表该怎么办
SELECTteam,SUM(CASEresultWHEN'胜'THEN1ELSE0END)ASwin,SUM(CASEresultWHEN'负'THEN1ELSE0END)asloss
FROM原表A
GROUPBYteam
Ⅳ sql 语句查询
select队名,
sum(casewhen胜负字段='胜'then1else0end)胜,
sum(casewhen胜负字段='负'then1else0end)负
from表名
groupby队名
你把相应的字段名和表名改一下就OK
Ⅵ 怎样写SQL语句结果是这样的
select日期,
sum(casewhen胜负=N'胜'then1else0end)as胜,
sum(casewhen胜负=N'负'then1else0end)as负
from表
groupby日期
Ⅶ 要求查询得到结果,写出sql语句
select tab2.日期,
(select count(1) from tab where tab.胜负 = '胜' and tab2.日期 = tab.日期),
(select count(1) from tab where tab.胜负 = '负' and tab2.日期 = tab.日期)
from
(select distinct 日期 from tab) tab2
Ⅷ SQL语句怎么写
select D.date,D.WIN as '胜',E.lose as '负'
from
(select date,win from(
SELECT date,
case when result = '胜' then count(result) else 0 end as 'win',
case when result = '负' then count(result) else 0 end as 'lose'
from T3
group by date,result
) C
where win > 0
group by date,C.win,C.lose) D,
(select date,lose from(
SELECT date,
case when result = '胜' then count(result) else 0 end as 'win',
case when result = '负' then count(result) else 0 end as 'lose'
from T3
group by date,result
) C
where lose > 0
group by date,C.win,C.lose) E
where E.date = D.date
-------------------------结果---------------
结果如下
date 胜 负
2007-07-01 00:00:00 2 2
2007-08-01 00:00:00 1 2