mysql - Merging 2 queries in Select COUNT(*) per day -
i have 2 tables logs , tracks each 1 holds timestamp different name try logs per day given shop , on same time number of tracks per day in tracks table
select date(clicktime), count(shop) log shop = "shop01" , (clicktime > date_sub(now(), interval 30 day)) group date(clicktime);
this query gathers entries in log table per day , result looks like
-------------------------------- clicktime | clicks -------------------------------- 2014-12-25 | 342 -------------------------------- 2014-12-24 | 232 --------------------------------
i sales per day on second table following
select date(last_change) saletime, count(shop) sale tracks shop = "dd01" , (last_change > date_sub(now(), interval 30 day)) , relevant = 1 group date(last_change)
outputs
-------------------------------- saletime | sales -------------------------------- 2014-12-25 | 42 -------------------------------- 2014-12-24 | 32 --------------------------------
and merge 2 queries in 1 to have output like
----------------------------------------- time | sales | clicks ----------------------------------------- 2014-12-25 | 42 | 342 ----------------------------------------- 2014-12-24 | 32 | 232 -----------------------------------------
i trying using union subquery 1 can't work in may case because different table structures
is there way achieve desired?
try this:
select a.clicktime, a.shopcnt, b.salecount (select date(clicktime) clicktime, count(shop) shopcnt log shop = "shop01" , (clicktime > date_sub(now(), interval 30 day)) group date(clicktime) ) inner join (select date(last_change) saletime, count(shop) salecount tracks shop = "dd01" , (last_change > date_sub(now(), interval 30 day)) , relevant = 1 group date(last_change) ) b on a.clicktime = b.saletime
Comments
Post a Comment