1. 表内容:
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 时间
当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);