难题!求一视图写法~100分相送!!
现有数据库表:
字段有
轮次 int
主队 varchar
客队 varchar
主队比分 int
客队比分 int
现要求一个视图
显示 胜、平、负、进球、失球
该如何写这个视图,写出来现场就给分!
问题点数:100、回复次数:17Top
1 楼caiyunxia(夏才云)回复于 2003-06-02 15:53:06 得分 5
select 轮次 , case when 主队比分>客队比分 then '胜' when 主队比分=客队比分 then '平' else '负' end,主队比分 进球,客队比分 失球
from tableTop
2 楼caiyunxia(夏才云)回复于 2003-06-02 15:55:47 得分 0
主队
select 轮次 ,主队 , case when 主队比分>客队比分 then '胜' when 主队比分=客队比分 then '平' else '负' end,主队比分 进球,客队比分 失球
from table
客队
select 轮次 ,客队 , case when 主队比分< 客队比分 then '胜' when 主队比分=客队比分 then '平' else '负' end,客队比分 进球 ,主队比分 失球 from table
Top
3 楼firetoucher(风焱)回复于 2003-06-02 15:56:52 得分 5
select 主队,客队,
case '胜' = when 主队比分>客队比分 then 1 else 0 end,
case '平' = when 主队比分=客队比分 then 1 else 0 end,
case '负' = when 主队比分<客队比分 then 1 else 0 end,
主队比分 进球,客队比分 失球
from tableTop
4 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 15:59:01 得分 0
胜、负是累加的,该如何写Top
5 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 15:59:54 得分 0
胜、负是累加的,该如何写牙,
哪位大侠有视图的相关语法资料,小弟感激不尽Top
6 楼lengtouxiaoer(愣头小二)回复于 2003-06-02 16:06:36 得分 10
Try
如果表内容为:
1 AC米兰 国际米兰 5 3
select 轮次 , 主队 ,case when 主队比分>客队比分 then '胜' when 主队比分=客队比分 then '平' else '负' end,主队比分 as 进球,客队比分 as 失球
from table
select 轮次 , 客队 ,case when 客队比分〉>主队比分 then '胜' when 客队比分=主队比分 then '平' else '负' end,客队比分 as 进球, 主队比分 as 失球
from table
Top
7 楼lengtouxiaoer(愣头小二)回复于 2003-06-02 16:08:20 得分 0
胜、负是累加的?什么意思?举个例子Top
8 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 16:15:45 得分 0
该程序为统计近几轮的比赛结果
比如在近六轮比赛中,某队作为主队或客队共参赛了6场,3胜、2平、1负
则实际数据表中每添加一条相关记录,视图中的“结果”也会作相应累加
不知这样我说清楚了没有 :)Top
9 楼janssenkm(正在贴鬼故事,却碰见了鬼)(!@#$%)回复于 2003-06-02 16:36:38 得分 0
配合几个函数就好了Top
10 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 16:43:24 得分 0
视图中如何使用函数,请不吝赐教!Top
11 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 17:00:00 得分 0
急阿!!Top
12 楼fhbkyo(光荣潜水员)回复于 2003-06-02 17:06:54 得分 0
GZTop
13 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 17:28:41 得分 0
我再定一下!!Top
14 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 18:30:37 得分 0
再顶Top
15 楼cpp2017(慕白兄)回复于 2003-06-02 18:35:22 得分 80
create view aa as
select
Team.team_name,( (Select count(轮次) from table1 where 主队=Team.team_name and 主队比分>客队比分)+
(Select count(轮次) from table1 where 客队=Team.team_name and 主队比分<客队比分)) as win,
(Select count(轮次) from table1 where 主队=Team.team_name and 主队比分<客队比分)+
(Select count(轮次) from table1 where 客队=Team.team_name and 主队比分>客队比分)
as lost,
((Select count(轮次) from table1 where 主队=Team.team_name and 主队比分=客队比分) +(Select count(轮次) from table1 where 客队=Team.team_name and 主队比分=客队比分 )) as equip
,
( (select isnull(sum(主队比分),0) from table1 where 主队=Team.team_name)+(select isnull(sum(客队比分),0) from table1 where 客队=Team.team_name)) as 进球,
((select isnull(sum(主队比分),0) from table1 where 客队=Team.team_name)+(select isnull(sum(客队比分),0) from table1 where 主队=Team.team_name)) as 失球
from
(select distinct 主队 as team_name from table1 union select distinct 客队 as team_name from table1) as Team
Top
16 楼tinyhuhu(~~~御风而行~~~)回复于 2003-06-02 18:47:25 得分 0
收到。
谢谢,散分!!~~~~Top
17 楼caiyunxia(夏才云)回复于 2003-06-02 18:52:00 得分 0
select 轮次 ,主队 球队 ,(select sum(case when (a.主队=主队 and 主队比分>客队比分) or (a.主队=客队 and 主队比分<客队比分) then 1 else 0 end) from table where int <=a.int ) as 胜,
(select sum(case when 主队比分=客队比分 then 1 else 0 end) from table where int <=a.int) as 平,
(select sum(case when (a.主队=主队 and 主队比分<客队比分) or (a.主队=客队 and 主队比分>客队比分) then 1 else 0 end) from table where int <=a.int) as 负 ,
(select sum(case then a.主队=主队 then 主队比分 when a.主队=客队 else 客队比分 else 0 end ) from table where int <=a.int) as 进球,
(select sum(case then a.主队=主队 then 客队比分 when a.主队=客队 else 主队比分 else 0 end ) from table where int <=a.int) as 失球
from table a
Top




