I have a table like this
id name amount
1 fish 120
1 meat 230
2 meat 110
2 fish 78
1 salad 50
3 meat 103
3 salad 22
2 salad 34
I want to write a query that will group names and sum their sum, but it should limit the first two identifiers, thus group elements by name and sum each corresponding name ... this should limit it to the first two identifiers, these are only identifiers 1 and 2 leaving id 3. Note. ID is a foreign key from another table.
This is what I tried. but it does not work
select name, sum(amount) from table1 group by amount, id order by id limit 2
this only outputs 2 results after doing the calculation
name amount
fish 198
meat 443
I expect something like this
name amount
fish 198
meat 340
salad 84
Add the number of elements with an identifier of only 1 and 2 and group them by name
source
share