2015-08-19 87 views
-4

我有兩個表算術級拼貼

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 

和狀態= A

最終 = SUM 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

學校工作?提示:JOIN和GROUP BY。 – jarlh

+0

你能幫助我嗎?它爲我的任務工作 – d2294

回答

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' 

任何簡單的答案?