I want to generate reprt like below. Date should come as columns, and each date sales across salesman and the total should come in rows. how can i get it thorugh MYSQL. My Table is X which is having all these details.
| Date 1 | Date 2 | Total |
-----------------------------------------------------------------
SalesmanName |Sales | Qty | Sales | Qty | TotSales | TotQty |
------------------------------------------------------------------
Salesman 1 | 100 | 10 | 100 | 10 | 200 | 20 |
------------------------------------------------------------------
Salesman 2 | 50 | 5 | 200 | 20 | 250 | 25 |
------------------------------------------------------------------
Table X:
salesmanname, salesvalue, salesquantity, transdate
(abc, 100, 10, 2015-07-01)
(xyz, 50, 5, 2015-07-01)
(abc, 90, 9, 2015-07-01)
(abc, 80, 8, 2015-07-01)
(xyz, 60, 6, 2015-07-02)
(abc, 40, 4, 2015-07-03)
(xyz, 100, 10, 2015-07-03)
(abc, 90, 9, 2015-07-04)
(xyz, 70, 7, 2015-07-04)
(xyz, 50, 5, 2015-07-04)
i tried with
select salesmanname, sum(sales), sum(qty) from x where trnsdate BETWEEN fromdate AND todate group by trnsdate,salesmanname
But i am not able to make the columns . How can i do the same. Please help me, i am new to MySql and queries.