Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 数据库查询_Mysql - Fatal编程技术网

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'

您是否尝试过查询您需要的数据…?您是否尝试过查询您需要的数据。。。?