How to write either mysql query or two diffrent queries with different result set can be converted into one array for a single table?
I have one table t1:
date company product sales
------------------------------------------------
2013-12-01 abc a1 100
2014-12-01 abc b1 50
2014-12-01 abc c1 100
2014-12-01 xyz x1 100
Query1 (based on selection of date='2014-12-01'):
--------------------------------------------------------
select company, sum(sales) as day_sales from t1 where date='2014-12-01'
group by company;
will give:
company day_sales
---------------------------
abc 150
xyz 100
Query2 (based on selection of date between '2014-12-01' and '2013-12-31'):
--------------------------------------------------------
select company, sum(sales) as previous_year_month_sale from t1
where date between '2013-12-01' and '2013-12-31' group by company;
will give:
company previous_year_month_sale
-----------------------------------
abc 100
How can i combine both results into one table like:
company day_sales previous_year_mtd
-----------------------------------------
abc 150 100
xyz 100 0
Please suggest?