您好,登錄后才能下訂單哦!
所有數(shù)學(xué)課程成績(jī) 大于 語(yǔ)文課程成績(jī)的學(xué)生的學(xué)號(hào)
CREATE TABLE course
(id
int,sid
int ,course
string,score
int
) ;
// 插入數(shù)據(jù)
// 字段解釋:id, 學(xué)號(hào), 課程, 成績(jī)
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);
求:所有數(shù)學(xué)課程成績(jī) 大于 語(yǔ)文課程成績(jī)的學(xué)生的學(xué)號(hào)
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;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。