‘壹’ 急求!用sql语句查询球队的胜率并进行排名
select 球队名称,胜利场数,失败场数,(胜利场数/失败场数)*100 as 胜率
from 球队排行表 order by 胜率
要是不行的话 请尝试
select 球队名称,胜利场数,失败场数,(胜利场数/失败场数)*100 as 胜率
from 球队排行表 order by (胜利场数/失败场数)*100
显示出%符号:
select 球队名称,胜利场数,失败场数,convert(varchar(10),(胜利场数/失败场数)*100+'%' as 胜率
from 球队排行表 order by (胜利场数/失败场数)*100
‘贰’ 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查询语句,ABC三只球队各有胜负,要生成下面的表该怎么办
SELECTteam,SUM(CASEresultWHEN'胜'THEN1ELSE0END)ASwin,SUM(CASEresultWHEN'负'THEN1ELSE0END)asloss
FROM原表A
GROUPBYteam
‘肆’ 一个只有 name的表 有name分别是 a b c d 四个球队 任意两个球队打比赛 一共会有几场比赛 用 sql语言表示
双循环对阵场次:
select a.name,b.name from test3 a,test3 b where a.name<>b.name
双循环比赛场数:
select count(*) from test3 a,test3 b where a.name<>b.name
单循环对阵场次:
select a.name,b.name from test3 a,test3 b where a.name<b.name
单循环比赛场数:
select count(*) from test3 a,test3 b where a.name<b.name
表名自己替换一下,我用的test3
欢迎追问
‘伍’ 帮忙写一句简单的sql语句,简直在送分~
--> --> (Roy)生成测试数据
if not object_id('Tempdb..#T') is null
drop table #T
Go
Create table #T([比赛] int,[数据类型] nvarchar(2),[数据值] nvarchar(2))
Insert #T
select 1,N'得分',N'10' union all
select 1,N'篮板',N'5' union all
select 1,N'助攻',N'2' union all
select 1,N'首发',N'是' union all
select 2,N'得分',N'20' union all
select 2,N'篮板',N'8' union all
select 2,N'助攻',N'3' union all
select 2,N'首发',N'否'union all
select 3,N'得分',N'20' union all
select 3,N'篮板',N'7' union all
select 3,N'助攻',N'5' union all
select 3,N'首发',N'是'
Go
Select
cast(sum(case when [数据类型]=N'得分' then [数据值] else 0 end)*1.0/count(distinct [比赛]) as decimal(18,2)) as 均场得分,
cast(sum(case when [数据类型]=N'篮板' then [数据值] else 0 end)*1.0/count(distinct [比赛])as decimal(18,2)) as 均场篮板,
cast(sum(case when [数据类型]=N'助攻' then [数据值] else 0 end)*1.0/count(distinct [比赛])as decimal(18,2)) as 均场助攻
from #T a
where
exists(select 1 from #T where [比赛]=a.[比赛] and [数据类型]=N'首发' and [数据值]='是')
(12 行受影响)
均场得分 均场篮板 均场助攻
--------------------------------------- --------------------------------------- ---------------------------------------
15.00 6.00 3.50
(1 行受影响)
‘陆’ sql查询语句问题
select race.RaceNumbers,
race.比赛日期,
t1.teamName,
t2.teamName,
m1.进球数,
m2.进球数,
from MatchScheles as race
inner join team as t1 on t1.TeamId = race.TeamId
inner join team as t2 on t2.TeamId = race.Tea_Teamid
inner join MatchInforma as m1 on m1.RaceNumbers = race.RaceNumbers and m1.TeamId = t1.TeamId
inner join MatchInforma as m2 on m2.RaceNumbers = race.raceNumbers and m2.TeamId = t2.TeamId
我能想到的就是这样了,可能不是最优的,不过应该能得到你要的结果。
至于把两个结果合成 3:2 就要看你用的是什么数据库了,把两个进球数和:拼接起来就好了。