I am struggling to find away to combine these 2 queries... ive tried subquerys, joins, unions and have had no luck :(
Query A
SELECT DATE(crtdtime) AS cntldate, sd_class, COUNT(crtdtime) AS created
FROM master
WHERE DATE(crtdtime) = '2011-11-16'
GROUP BY cntldate, sd_class
Which produces
+------------+----------+---------+
| cntldate | sd_class | created |
+------------+----------+---------+
| 2011-11-16 | CUST | 2226 |
| 2011-11-16 | NET | 238 |
+------------+----------+---------+
Query B
SELECT DATE(rstdtime) AS cntldate, sd_class, COUNT(rstdtime) AS restored
FROM master
WHERE DATE(rstdtime) = '2011-11-16'
GROUP BY cntldate, sd_class
Which produces
+------------+----------+----------+
| cntldate | sd_class | restored |
+------------+----------+----------+
| 2011-11-16 | CUST | 2315 |
| 2011-11-16 | NET | 221 |
+------------+----------+----------+
But would like the end result to be...
+------------+----------+---------+----------+
| cntldate | sd_class | created | restored |
+------------+----------+---------+----------+
| 2011-11-16 | CUST | 2226 | 2315 |
| 2011-11-16 | NET | 238 | 221 |
+------------+----------+---------+----------+
Would greatly appreciate any help.
Thank you.
one possible way
SELECT DATE(crtdtime) AS cntldate,
sd_class,
sum( DATE(crtdtime) = '2011-11-16') AS created
sum( DATE(rstdtime) = '2011-11-16') AS restored
FROM master
WHERE DATE(crtdtime) = '2011-11-16' or DATE(rstdtime) = '2011-11-16'
GROUP BY cntldate, sd_class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With