Trying to find: Show the top-20 PIs who have the largest total amount of awards along with the universities they are affliated with.
Mysql开发者_JAVA百科
SELECT max(award), pi, org
FROM iis
LIMIT 20;
This only gives me and I want the top 20 records:
Table
Anyone??
If the awards are not already totaled, then you want to find the sum of the awards for each PI, you need to use SUM, and GROUP BY pi, to sum the awards for each PI
SELECT SUM(award) AS totalAwards, pi, org
FROM iis
GROUP BY pi, org
ORDER BY SUM(award) DESC
LIMIT 20;
SELECT award, pi, org
FROM iis
ORDER BY award DESC
LIMIT 20;
精彩评论