mysql - How can I combine two queries with a having clause into one? -
i hope can me these 2 queries query:
select count(distinct id), sum(amount) sales year(saledate) = '2015' , saletype ='cash' group customer having sum(amount) >=500; select count(distinct id), sum(amount) sales year(saledate) = '2015' , saletype ='creditcard' group customer having sum(amount) >=1000;
what best way combine them one? aim select cases customer paid more 500 in cash or more 1000 via creditcard.
thanks lot help.
in case can use example:
select count(distinct id), sum(amount) sales year(saledate) = '2015' , saletype ='cash' group customer having sum(amount) >=500; union select count(distinct id), sum(amount) sales year(saledate) = '2015' , saletype ='creditcard' group customer having sum(amount) >=1000;
or union if want records without distinct.
select count(distinct id), sum(amount) sales year(saledate) = '2015' , saletype ='cash' group customer having sum(amount) >=500; union select count(distinct id), sum(amount) sales year(saledate) = '2015' , saletype ='creditcard' group customer having sum(amount) >=1000;
Comments
Post a Comment