$query1 = 'select DATE_FORMAT(time, "%Y-%m-%d") as date,
count(*) as phone_TotalPerDay
from numrequest
where id_usr = "'.$id_user.'"
AND id_re ="'.$id_re.'"
AND request="ph"
group by id_usr, year(time), DAYOFYEAR(time)
order by year(time) DESC, DAYOFYEAR(time) DESC';
$query2 = 'select DATE_FORMAT(time, "%Y-%m-%d") as date,
count(*) as fax_TotalPerDay
from numrequest
where id_usr = "'.$id_user.'"
AND id_re ="'.$id_re.'"
AND request="fx"
group by id_usr, year(time), DAYOFYEAR(time)
order by year(time) DESC, DAYOFYEAR(time) DESC';
Is there a way to combine these two queries. I really need them in one resource.
currently each one is showing number of number request per day. I want to combine them so that each date has phone_TotalPerDay and fax_TotalPerDay.
You could use a conditional sum, something like
The
ifstatements return 1 if the request type matches and 0 otherwise, so summing these effectively counts the rows matching this condition, and I’ve removed the request criteria from the where clause.