查询每门课程成绩都大于80分学生的姓名
(2015-04-22 14:24:38)
标签:
教育 |
分类: java |
转载的sql语句
.1 查询每门课程成绩都大于80分学生的学号
数据库 表 student
name score course
A 85
A 75
A 82
B
B
B
天使美眉90 语文
天使美眉100 数学
天使美眉100 英语
请找出每门课程都超过80分的那个人名字的SQL语句
SQL1:
select name from test.stu
group by name
having count(score) =sum(case
SQL2:
select name from stu
group by name
having name not in (
select name from stu
where score <80)
SQL3:
select name from test.stu
group by name
having min(score)>=80
================================================
2. 查询课程001的成绩大于课程002成绩的学号
student表:sno(学号),sname(姓名),sex(性别),dept(系)
course课程表:cno(课程号),课程名(cname)
sc选课表:sno,cno,grade(成绩)
select cno from sc a inner join (select * from sc where cno=(select
cno from course where cname='001')) as b on a.cno>o=(select cno
from course where cname='002')
================================================
3、关于group by表内容:
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
2005-05-10
--------------------------------------------------------
1) select rq,sum(case when shengfu='胜' then 1 else 0 end)
as胜,sum(case when shengfu='负' then 1 else 0 end) as负from tab3 group
by rq
2) select N.rq,N. 胜,M. 负 from
(select rq,count(*) 胜 from tab3 where shengfu='胜'group by rq)N
inner join
(select rq,count(*) 负from tab3 where shengfu='负'group by rq)M on
N.rq=M.rq
3) select a.rq,a. 胜
(select rq,count(shengfu) 胜from tab3 where shengfu='胜' group by rq)
a,
(select rq,count(shengfu) 负from tab3 where shengfu='负' group by rq)
b
where a.rq=b.rq;
4)select time, sum(decode(status,'胜','')) 胜
,sum(decode(status,'负','')) 负 from shengfu_table group by time;
======================================================
4.表中有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 else c end) from tab4
5.一个日期判断的sql语句请取出tab5表中日期(SendTime字段)为当天的所有记录
(SendTime字段为datetime型,包含日期与时间)
select * from tab5 t where
to_char(t.SendTime,'yyyy-mm-dd')=to_char(sysdate,'yyyy-mm-dd')
6.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):
-------------------------------------------------------
select
(case when语文>=80 then '优秀' when语文>60 then '及格' else '不及格'
end) as 语文,
(case when 数学>=80 then '优秀' when数学>60 then '及格' else '不及格'
end) as数学,
(case when英语>=80 then '优秀' when英语>60 then '及格' else '不及格'
end) as 英语
from tab5
==================================
7.请用一个sql语句得出结果
从table1,table2中取出如table3所列格式数据
table1
月份mon
-------------------------------
一月份
一月份
一月份
二月份
二月份
三月份
table2
部门dep
--------------------------------
table3 (result)
部门dep