我正在尝试创建一个MS Access查询以显示两个类别的分数。 A类和B类。我试图选择总成绩最高的前3名学生,但我不确定该怎么做。现在,我通过他们的NIM(学生证件)来订购它
我尝试用其他替代方式替换该订单,例如SUM(xx)/ sum(xx)DESC,但它不起作用。你能帮我指出吗?
SELECT *
FROM
(
SELECT
m.NIM AS NIM
, m.Nama_Mhs AS Nama_Mhs
, n.Kelas AS Kelas
, n.Tahun_Akademik AS Tahun
, SUM(k.SKS * Switch(n.Huruf ='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0)) AS NilaiTotalA
, ROUND(NilaiTotalA / SUM(k.SKS), 2) As NilaiIPKA
FROM
(Master_Mahasiswa m
INNER JOIN
Nilai n
On
m.NIM=n.NIM)
INNER JOIN
Master_MK k
On
k.Kode_MK=n.Kode_MK
GROUP BY
m.NIM
, m.Nama_Mhs
, n.Kelas
, n.Tahun_Akademik
HAVING
n.Kelas ='IK - 2A'
ORDER BY
SUM(k.SKS*SWITCH(n.Huruf='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0))/SUM(k.SKS) DESC
)
sub1
RIGHT JOIN
(
SELECT
TOP 3 m.NIM AS NIM
, m.Nama_Mhs AS Nama_Mhs
, n.Kelas AS Kelas
, n.Tahun_Akademik AS Tahun
, SUM(k.SKS *SWITCH(n.Huruf='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0)) AS NilaiTotalB
, ROUND(NilaiTotalB/SUM(k.SKS), 2) AS NilaiIPKB
FROM
(Master_Mahasiswa m
INNER JOIN
Nilai n
ON
m.NIM=n.NIM)
INNER JOIN
Master_MK k
ON
k.Kode_MK=n.Kode_MK
GROUP BY
m.NIM
, m.Nama_Mhs
, n.Kelas
, n.Tahun_Akademik
HAVING
n.Kelas ='IK - 2B'
ORDER BY
SUM(k.SKS*SWITCH(n.Huruf='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0))/SUM(k.SKS) DESC
)
sub2
ON
MID(sub1.NIM, 11, 2)=MID(sub2.NIM, 11, 2)
ORDER BY
sub2.NIM
UNION
SELECT *
FROM
(
SELECT
TOP 3 m.NIM As NIM
, m.Nama_Mhs As Nama_Mhs
, n.Kelas As Kelas
, n.Tahun_Akademik As Tahun
, SUM(k.SKS * Switch(n.Huruf ='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0)) AS NilaiTotalA
, ROUND(NilaiTotalA/SUM(k.SKS), 2) AS NilaiIPKA
FROM
(Master_Mahasiswa m
INNER JOIN
Nilai n
ON
m.NIM=n.NIM)
INNER JOIN
Master_MK k
ON
k.Kode_MK=n.Kode_MK
GROUP BY
m.NIM
, m.Nama_Mhs
, n.Kelas
, n.Tahun_Akademik
HAVING
n.Kelas ='IK - 2A'
ORDER BY
SUM(k.SKS*SWITCH(n.Huruf='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0))/SUM(k.SKS) DESC
)
sub1
LEFT JOIN
(
SELECT
m.NIM AS NIM
, m.Nama_Mhs AS Nama_Mhs
, n.Kelas AS Kelas
, n.Tahun_Akademik AS Tahun
, SUM(k.SKS *SWITCH(n.Huruf='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0)) AS NilaiTotalB
, ROUND(NilaiTotalB/SUM(k.SKS), 2) AS NilaiIPKB
FROM
(Master_Mahasiswa m
INNER JOIN
Nilai n
ON
m.NIM=n.NIM)
INNER JOIN
Master_MK k
ON
k.Kode_MK=n.Kode_MK
GROUP BY
m.NIM
, m.Nama_Mhs
, n.Kelas
, n.Tahun_Akademik
HAVING
n.Kelas ='IK - 2B'
ORDER BY
SUM(k.SKS*SWITCH(n.Huruf='A', 4, n.Huruf='B', 3, n.Huruf='C', 2, n.Huruf='D', 1, TRUE, 0))/SUM(k.SKS) DESC
)
sub2
ON
MID(sub1.NIM, 11, 2)=MID(sub2.NIM, 11, 2)
ORDER BY
sub2.NIM
;
我正在尝试按“ NilaiIPKA”(基本上是A类的平均分数)和“ NilaiIPKB”(是b类的平均分数)排序。我该怎么做?有人可以帮忙查询吗?我需要尽快完成此操作。谢谢
对不起,如果代码有点凌乱,我不知道如何在此处进行实际排列。这是我的MS Access查询https://imgur.com/yzsTRCQ
的屏幕截图