sql一些小查询语句

1. 表内容:

        2005-05-09 胜

        2005-05-09 胜

        2005-05-09 负

        2005-05-09 负

        2005-05-10 胜

        2005-05-10 负

        2005-05-10 负  

    如果要生成下列结果, 该如何写sql语句?  

                   胜 负

        2005-05-09  2 2

        2005-05-10  1 2

select 时间,

SUM(case when win='' then 1 else 0 end) ,

SUM(case when win='' then 1 else 0 end) 

from tb

group by 时间

 

2. 表中有A B C三列,用SQL语句实现

    当A列大于B列时选择A列否则选择B列

当B列大于C列时选择B列否则选择C列

select (case when a>b then a else b end),
(case when b>c then b esle c end)
from table_name

 

 

 

3. 有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记 录并按以下条件显示出来(并写出您的思路):  大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。

    显示格式:           

        语文              数学                英语          

        及格              优秀                不及格

Select case when 语文 >= 80 then 优秀when 语文 >= 60 then 及格else 不及格 end 语文,case when 数学 >= 80 then 优秀when 数学 >= 60 then 及格else 不及格 end 数学,case when 英语 >= 80 then 优秀when 英语 >= 60 then 及格else 不及格 end 英语 form 表名;

4. 用一条SQL 语句 查询出每门课都大于80 分的学生姓名

    name   kecheng   fenshu

    张三     语文       81

    张三     数学       75

    李四     语文       76

    李四     数学       90

    王五     语文       81

    王五     数学       100

王五     英语       90

 

Select distinct[name] form where name not in(Select name form 表名 where fenshu <= 80);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值