| 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 try to get only 3 records for makers , the top 3 amounts and widgets they produced
Here is what I have:
SELECT amount, makers FROM (SELECT amount, makers, (SELECT count(*) FROM entry as t2 WHERE t2.amount = t1.amount and t2.makers >= t1.makers) AS RowNum FROM entry as t1 ) t3 WHERE t3.RowNum<4 order by amount;
Is this what I really need? Is there a better way to do this? Most of the ways I've seen for this make connections, etc. On scattered tables, all the information I need is on the same table.
Expected Result:
| uId | title | amounts | makers | widgets | 1 richard 998 xcorp sprocket 41 swiss 995 xcorp widget 989 richard 989 xcorp sprocket 22 swiss 995 ycorp framitz 92 swiss 990 ycorp widget 456 swiss 895 ycorp flobber 344 ricky 490 zcorp flobber 32 tricky 480 zcorp flobber 13 ricky 470 zcorp flobber
etc...
The order of the makers does not matter, since getting the top 3 amounts for each makers and widgets they have provided. The number of makers , there will always be x makers
source share