勝負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