SELECT id name subject score FROM scores ORDER BY score DESC; 然后取第一个和最后一个的姓名
To retrieve the name of the first and last person in the scores table, you can use the following SQL query:
SELECT name
FROM scores
ORDER BY score DESC
LIMIT 1
UNION
SELECT name
FROM scores
ORDER BY score DESC
LIMIT 1
OFFSET (SELECT COUNT(*) FROM scores) - 1;
This query first retrieves the name of the person with the highest score (first row) using the LIMIT 1 clause and ordering by score in descending order. Then, it uses the UNION operator to combine the result with the name of the person with the lowest score (last row). The LIMIT 1 clause is also used here, but with an OFFSET equal to the count of rows in the scores table minus 1, which gives the last row
原文地址: http://www.cveoy.top/t/topic/iyUq 著作权归作者所有。请勿转载和采集!