17,086
社区成员
发帖
与我相关
我的任务
分享
select stu_name,class_id,lession_name
from
(select stu_id,stu_name,class_id,lession_id,lession_name
from T_Stu_Profile,T_Lession) b
where not exists(select 1 from t_score c
where c.stu_id=b.stu_id
and c.lession_id=b.lession_id);
select lession_name,
max(case when rn=1 then stu_name||score end) first,
max(case when rn=2 then stu_name||score end) second,
max(case when rn=3 then stu_name||score end) third
from
(select a.lession_name,c.stu_name,b.score,b.rn
from t_lession a,(
select stu_id,lession_id,score,row_number() over(partition by lession_id order by score desc) rn
from T_Score) b,
T_Stu_Profile c
where a.lession_id=b.lession_id
and c.stu_id=b.stu_id
and b.rn<=3) d
group by lession_name;
select stu_name,sum(decode(lession_id,'L001',score,0)) "语文",
sum(decode(lession_id,'L002',score,0)) "数学",
sum(decode(lession_id,'L003',score,0)) "外语",
sum(decode(lession_id,'L004',score,0)) "物理",
sum(decode(lession_id,'L005',score,0)) "化学",
sum(score) "总分"
from
(select stu_name,lession_id,score
from t_stu_profile a,t_score b
where a.stu_id=b.stu_id
and a.class_id='0611')
group by stu_name;
Select Stu_id,Sum(yw),
Sum(sx),Sum(yy),Sum(wl),Sum(hx) ,Sum(Score)
from
(
Select A.Stu_id,
Case when Lession_Name = '语文' then ISNULL(Cast(Score as int),0) end AS 'yw',
Case when Lession_Name = '数据' then ISNULL(Cast(Score as int),0) end AS sx,
Case when Lession_Name = '英语' then ISNULL(Cast(Score as int),0) end AS yy,
Case when Lession_Name = '物理' then ISNULL(Cast(Score as int),0) end AS wl,
Case when Lession_Name = '化学' then ISNULL(Cast(Score as int),0) end AS hx,
ISNULL(Cast(Score as int),0) AS Score
From T_Stu_Profile A
Left Join T_Lession B On 1=1
Left Join T_Score C
On A.Stu_id = C.Stu_id AND B.Lession_id = C.Lession_id
Where C.Score is not null
)B Group by Stu_id
Select A.Stu_id,A.Stu_Name,A.Class_ID,Lession_Name
From T_Stu_Profile A
Left Join T_Lession B On 1=1
Left Join T_Score C
On A.Stu_id = C.Stu_id AND B.Lession_id = C.Lession_id
Where C.Score is null
1:
SELECT DISTINCT
LESS1.STU_ID,
SCORE.LESSION_ID,
SCORE.LESSION_NAME
FROM T_SESSION LESS1,
T_SCORE SCORE
WHERE SCORE.LESSION_ID NOT IN (
SELECT LESS2.LESSION_ID
FROM T_SESSION LESS2
WHERE LESS1.STU_ID = LESS2.STU_ID
)
;
或者用minus实现也可以
2: 级别排位问题+max()
3: 行变列(包括总分sum(...))