Reputation: 3
basically I'm having some troubles trying to group all rows by their type except the only which is called lets say "test", this one is meant to be ignored but displayed apart if its possible, but I can't really find a solution, thanks in advance!
SELECT *, SUM(amount) as 'amount' FROM history WHERE date = '$date' GROUP BY type
The query which is above is grouping all rows including the one I'm trying to ignore
Upvotes: 0
Views: 508
Reputation: 780724
You can use:
GROUP BY type, IF(type = "test", id, 0)
Replace id
with the primary key of the table.
When type is test
this uses the primary key as a secondary grouping field, so all those rows will be in separate groups. For all other types, the secondary group will be equal for all items, so they don't get subgroups.
Upvotes: 2