Mysql 数据库查询
如何看待这一点 问题:每个Mysql 数据库查询,mysql,Mysql,如何看待这一点 问题:每个sProgram中年龄最大的学生 表名为Student 栏目包括: sID, sLast, sFirst, sMI, sProgram, sGender, sAge 样本数据: sID sLast sFirst sMI sProgram sGender sAge ------------------------------------------------------- 001 Right Mc D B
sProgram
中年龄最大的学生
表名为Student
栏目包括:
sID, sLast, sFirst, sMI, sProgram, sGender, sAge
样本数据:
sID sLast sFirst sMI sProgram sGender sAge
-------------------------------------------------------
001 Right Mc D BSIT M 26
002 Michael John G BSIT M 22
002 Franco James D BSCPE M 20
003 Step Ren D BSECE M 22
我想展示BSIT最年长的学生
所需输出为:
001 , Right, Mc, D, BSIT, M, 26
如果您只想要“BSID”中年龄最大的学生,您可以尝试以下方法:
SELECT *
FROM Student
WHERE sProgram = 'BSIT'
ORDER BY sAge DESC
LIMIT 1
或者,如果您想要每个程序中年龄最大的学生,您可以这样做:
SELECT t1.*
FROM Student t1
JOIN (
SELECT sProgram, MAX(sAge) AS sAge FROM Student GROUP BY sProgram
) t2 ON t1.sProgram = t2.sProgram AND t1.sAge = t2.sAge
-- WHERE t1.sProgram = 'BSIT'
如果您只想要“BSID”中年龄最大的学生,您可以尝试以下方法:
SELECT *
FROM Student
WHERE sProgram = 'BSIT'
ORDER BY sAge DESC
LIMIT 1
或者,如果您想要每个程序中年龄最大的学生,您可以这样做:
SELECT t1.*
FROM Student t1
JOIN (
SELECT sProgram, MAX(sAge) AS sAge FROM Student GROUP BY sProgram
) t2 ON t1.sProgram = t2.sProgram AND t1.sAge = t2.sAge
-- WHERE t1.sProgram = 'BSIT'
您是否尝试过查询您需要的数据…?您是否尝试过查询您需要的数据。。。?