十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
所有数学课程成绩 大于 语文课程成绩的学生的学号
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站制作、成都网站建设、武陟网络推广、成都小程序开发、武陟网络营销、武陟企业策划、武陟品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供武陟建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com
CREATE TABLE course
(id
int,sid
int ,course
string,score
int
) ;
// 插入数据
// 字段解释:id, 学号, 课程, 成绩
INSERT INTO course
VALUES (1, 1, 'yuwen', 43);
INSERT INTO course
VALUES (2, 1, 'shuxue', 55);
INSERT INTO course
VALUES (3, 2, 'yuwen', 77);
INSERT INTO course
VALUES (4, 2, 'shuxue', 88);
INSERT INTO course
VALUES (5, 3, 'yuwen', 98);
INSERT INTO course
VALUES (6, 3, 'shuxue', 65);
求:所有数学课程成绩 大于 语文课程成绩的学生的学号
select sid,case when course="yuwen" then score else 0 end as yuwen,
case when course="shuxue" then score else 0 end as shuxue
from course;
1 43 0
1 0 55
2 77 0
2 0 88
3 98 0
3 0 65
select tmp.sid,Max(tmp.yuwen) as yuwen,max(tmp.shuxue) as shuxue
from(
select sid,case when course="yuwen" then score else 0 end as yuwen,
case when course="shuxue" then score else 0 end as shuxue
from course
) tmp
group by tmp.sid;
1 43 55
2 77 88
3 98 65
select stmp.sid
from (
select tmp.sid,Max(tmp.yuwen) as yuwen,max(tmp.shuxue) as shuxue
from(
select sid,case when course="yuwen" then score else 0 end as yuwen,
case when course="shuxue" then score else 0 end as shuxue
from course
) tmp
group by tmp.sid
) stmp where stmp.shuxue > stmp.yuwen;