有一张学生表student。里面有姓名,课程名称,成绩三个字段.
包含如下数据:
姓名name course grade
王明 语文 95
王明 数学 85
王明 英语 92
王明 物理 93
王明 化学 90
王明 生物 85
王明 政治 84
张波 语文 95
张波 数学 90
张波 英语 92
张波 物理 93
张波 化学 89
张波 生物 99
张波 政治 95
......................
......................
请查询出至少有三科成绩不低于90分的学生姓名和成绩
又是你哦,上次company那题该给我分了吧
[code="sql"]
SELECT t.NAME, t.grade
FROM student t
WHERE t.NAME IN (SELECT NAME
FROM student
WHERE grade >= 90
GROUP BY NAME
HAVING(COUNT(*) >= 3));
[/code]
敢问这张表的主键是name吗?
表create table student_temp(
stname varchar2(25),
stcourse varchar2(25),
stscore number(3));
数据
insert into student_temp values ('ryhn','oracle',90);
insert into student_temp values ('ryhn','php',70);
insert into student_temp values ('ryhn','java',89);
insert into student_temp values ('ryhn','c++',98);
insert into student_temp values ('tyler','oracle',92);
insert into student_temp values ('tyler','php',88);
insert into student_temp values ('tyler','java',77);
insert into student_temp values ('tyler','c++',66);
insert into student_temp values ('gavin','oracle',99);
insert into student_temp values ('gavin','php',100);
insert into student_temp values ('gavin','java',90);
insert into student_temp values ('gavin','c++',96);
insert into student_temp values ('sean','oracle',97);
insert into student_temp values ('sean','php',80);
insert into student_temp values ('sean','java',91);
insert into student_temp values ('sean','c++',95);
要求至少两科成绩不小于90.
select b.stname, b.stscore from student_temp b where b.stname in (select a.stname from (select stname, case when stscore >= 90 THEN 'A' else 'F' end qualified from student_temp) a
group by a.stname having sum(case when a.qualified = 'A' then 1 end) >= 2)
不知道是不是你想要的。