Reputation: 3
I want to combine the results of two queries into one resulttable
with three columns, result1
, result2
and dateday
, the queries are contradictory
SELECT COUNT( DISTINCT `cust` ) AS result1, DATE( `date` ) AS dateday
FROM `salg_test`
WHERE `saved` =0
AND `is_void` =0
GROUP BY dateday
ORDER BY dateday DESC
SELECT COUNT( DISTINCT `cust` ) AS result2, DATE( `date` ) AS dateday
FROM `salg_test`
WHERE `saved` =1
AND `is_void` =0
GROUP BY dateday
ORDER BY dateday DESC
I want both results to be grouped by and ordered by the dateday
variable.
Upvotes: 0
Views: 108
Reputation: 852
Should be able to do something like this:
SELECT COUNT( DISTINCT CASE `saved` when 0 then `cust` else null end ) AS result1
, COUNT( DISTINCT CASE `saved` when 1 then `cust` else null end ) AS result2
, DATE( `date` ) AS dateday
FROM `salg_test`
WHERE `is_void` =0
GROUP BY dateday
ORDER BY dateday DESC
Upvotes: 2
Reputation: 5183
how about:
WHERE (`saved`= 1 OR `saved`= 0)
Or, if the only possible values of saved
are 1 or 0, just omit that condition from the query altogether.
Upvotes: 0