PostgreSQL: top n entries per item in same table
问题 | uId | title | amount | makers | widgets | 1 richard 998 xcorp sprocket 2 swiss 995 ycorp framitz 3 ricky 90 zcorp flobber 4 ricky2 798 xcorp framitz 1 lilrick 390 xcorp sprocket 1 brie 200 mcorp gullywok 1 richard 190 rcorp flumitz 1 brie 490 bcorp sprocket etc... I am trying to retrieve only 3 records per makers , the top 3 amounts and the widgets they produced Here's is what I have: SELECT amount, makers FROM (SELECT amount, makers, (SELECT count(*) FROM entry as t2 WHERE t2.amount = t1