我有两张桌子
table a
nim 01 01 01 02 02 02 03 03 03 04 04 04 05 05 05
task t m f t m f t m f t m f t m
grade 70 80 85 75 65 75 70 80 85 70 80 84 72 50 65
注意:t =任务m =中间f =结局
table b
nim 01 02 03 04 05
name lius leo eris calvin kevin
status A A I I A
注意:A = Avaliable,I =无效
现在我要展示
no name nim t m f t1 m1 f1 final grade
note t1= tx0.2
m1 = mx0.3
f1 = fx0.5
和status = A
最终 =总和t1,m1,f1
for grade
grade a >=85
grade b>=75
grade c >=65
我卡在这里
SELECT DISTINCT b.NIM,TM,MID,FINAL,[Poin T],[Poin M],[Poin F],FLOOR([Poin T]+[Poin M]+[Poin F])AS NilaiAkhir,
CASE WHEN ([Poin T]+[Poin M]+[Poin F])>84.9 AND ([Poin T]+[Poin M]+[Poin F])<=100 THEN 'A'
WHEN ([Poin T]+[Poin M]+[Poin F])>74.9 AND ([Poin T]+[Poin M]+[Poin F])<=85 THEN 'B'
WHEN ([Poin T]+[Poin M]+[Poin F])>64.9 AND ([Poin T]+[Poin M]+[Poin F])<=75 THEN 'C'
ELSE 'D' END AS Grade
FROM Mahasiswa a,
(SELECT NIM, TM=Nilai FROM Mahasiswa WHERE Tipe LIKE 'TM') b,
(SELECT NIM, MID=Nilai FROM Mahasiswa WHERE Tipe LIKE 'MID')c,
(SELECT NIM, FINAL=Nilai FROM Mahasiswa WHERE Tipe LIKE 'FINAL')d,
(SELECT NIM, [Poin T]=Nilai*0.2 FROM Mahasiswa WHERE Tipe LIKE 'TM' )e,
(SELECT NIM, [Poin M]=Nilai*0.3 FROM Mahasiswa WHERE Tipe LIKE 'MID' )f,
(SELECT NIM, [Poin F]=Nilai*0.5 FROM Mahasiswa WHERE Tipe LIKE 'FINAL' )g
WHERE a.NIM=b.NIM AND a.NIM=c.NIM AND a.NIM=d.NIM AND a.NIM=e.NIM AND a.NIM=f.NIM AND a.NIM=g.NIM
答案 0 :(得分:0)
select row_number () over (order by e.nim) as no , e.Nim,TM,Mid,Fin,T1,M1,F1,CEILING(T1+M1+F1) as score,
case WHEN (T1+M1+F1)>84.9 AND (T1+M1+F1)<=100 THEN 'A'
WHEN (T1+M1+F1)>74.9 AND (T1+M1+F1)<=85 THEN 'B'
WHEN (T1+M1+F1)>64.9 AND (T1+M1+F1)<=75 THEN 'C'
ELSE 'D' END AS Grade
FROM
(select nim,tm,mid,fin
from Tablemhs
pivot
(
sum (grade)
for task in (Tm,Mid,Fin))as a)e,
(Select Nim, T1= (grade*0.2) from Tablemhs where Task like 'TM') b,
(Select Nim, M1= grade*0.3 from Tablemhs where Task like 'MID') c,
(Select Nim, F1= grade*0.5 from Tablemhs where Task like 'FIN') d,
Tablestatus f
where e.Nim=b.nim and e.Nim=c.Nim and e.Nim=d.Nim and f.Nim=e.Nim and status like'A'
任何简单的答案?