我是第一次学习 SQL,我被要求做这些查询。
我写了这些语句来解决问题,它们有效,但它们不使用group by
.
有人可以建议我如何改变这个吗?他们应该只使用group by
并且也许where
,我认为这个任务不应该使用更高级的东西。
总统的最新出生日期是什么时候?(最年轻的总统)
SELECT birth, first_name, last_name
FROM sampdb.president
WHERE birth= (select MAX(birth) FROM sampdb.president);
+------------+------------+-----------+
| birth | first_name | last_name |
+------------+------------+-----------+
| 1946-08-19 | William J. | Clinton |
+------------+------------+-----------+
1 row in set (0.00 sec)
SELECT birth, first_name, last_name
FROM sampdb.president
WHERE birth>=ALL(SELECT MAX(birth) FROM sampdb.president);
+------------+------------+-----------+
| birth | first_name | last_name |
+------------+------------+-----------+
| 1946-08-19 | William J. | Clinton |
+------------+------------+-----------+
1 row in set (0.00 sec)
最早的?(最年长的总统)
SELECT birth, first_name, last_name
FROM sampdb.president
WHERE birth=(SELECT MIN(birth) FROM sampdb.president);
+------------+------------+------------+
| birth | first_name | last_name |
+------------+------------+------------+
| 1732-02-22 | George | Washington |
+------------+------------+------------+
1 row in set (0.00 sec)