group by - Mysql: grouping a data by multiple fields -


i have mysql table this

id       criteria1    criteria2   amount 1           'a'          'b'         100 2           'a'          'c'          20 3           'd'          'b'          30 

i need write group query in such way final output should be

criteriamatch      sum(amount) criteria2 = b         130 criteria1 =         120 

data id 1 overlaps in both condition.

how achieve this?

i tried using mysql case. in case when first criteria matches, data skips second condition , dont intended result.

you create 2 separate queries, first grouping criteria 1 , second criteria 2, along proper filters in each one. so, this:

select criteria1 'criteria',sum(amt) yourtable (criteria1 = 'a') group criteria1 union select criteria2 'criteria',sum(amt) yourtable (criteria2 = 'b') group criteria2 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -