Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我被要求从表格中找到每个评分的最低年龄,如下所示:
table name: 'SAILORS' fields: 'SID', 'SNAME', 'Rating', 'Age**'
这可以使用 PHP 来完成,但我必须使用 MYSQL 查询来完成。
一个group by over Ratingcolumn 和min函数调用将做到这一点。
Rating
SELECT Min(`Age`) AS `Lowest Age`, `Rating` FROM `SAILORS` GROUP BY `Rating`
select Rating, min(Age) as MinAge from SAILORS group by Rating
这是一个简单的分组查询:
select Rating, min(Age) from SAILORS group by Rating