CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  基础类

难题!求一视图写法~100分相送!!

楼主tinyhuhu(~~~御风而行~~~)2003-06-02 15:48:05 在 MS-SQL Server / 基础类 提问

现有数据库表:  
  字段有  
   
  轮次   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

相关问题

  • 100求视图的写法
  • 跪求一视图写法
  • 一个视图写法,请指教
  • 请教一个视图的写法
  • 求视图写法(四个表) 100分
  • 视图难题,请高手解决!
  • 高分求一个视图(SQL语句)的写法
  • 100求一个简单视图的写法.
  • 请教一个难题,关于视图嵌套。
  • 200分求一<<<<<<<<<巨难视图SQL语句>>>>>>>>>的写法。UP有分!谢谢各位帮忙!!!

关键词

  • 视图
  • 比分
  • 主队
  • 客队
  • team
  • 进球
  • 失球
  • isnull
  • sum
  • then

得分解答快速导航

  • 帖主:tinyhuhu
  • caiyunxia
  • firetoucher
  • lengtouxiaoer
  • cpp2017

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo