Hi ,
I have 200 clients and i want to show their details with products and count like this :
Client 1
Week Open Close
Product 1
Product 2
Product 3
Client 2
Week Open Close
Product 1
Product 2
Product 3
Through filters i can do this with cross tabulation but i want to show all clients in their separate tables. I can't hard code the client name in query for 200 clients.. Plus it should be dynamic, if the entries of client is not coming in date range, it should not show that client.
With filters my query is :
select 'dbr.crosstab', 'ClientOrganization';
select 'dbr.hsum', 'Open','Close';
select 'dbr.sum', 'Open','Close';
SELECT Product,ClientOrganization , Month,
week,
sum(open) AS Open,
sum(close)as Close
FROM (
SELECT ClientOrganization, Product, CONCAT(SubmissionMonth,'-', SubmissionYear) as Month,
WEEK(Submission,5) -
WEEK(DATE_SUB(Submission, INTERVAL DAYOFMONTH(Submission)-1 DAY),5) as week,
count(*) AS open,
0 as close,SubmissionYear as Year,month(Submission) as mon
FROM wf_frmwrk.tps_tbl_master_all_coumns
-- where SubmissionYear=year(curdate())
where (ClientOrganization = Org or Org='All')
and (Product = Pro or Pro = 'All')
AND Submission between StartDate and EndDate
GROUP BY ClientOrganization, Product, Month, week
UNION ALL
SELECT ClientOrganization, Product,CONCAT(LatestClosedMonth,'-',LatestClosedYear) AS Month,
WEEK(LatestClosed,5) -
WEEK(DATE_SUB(LatestClosed, INTERVAL DAYOFMONTH(LatestClosed)-1 DAY),5) as week,
0 as open,
count(*) close,LatestClosedYear as Year,month(LatestClosed) as mon
FROM wf_frmwrk.tps_tbl_master_all_coumns
-- where LatestClosedYear=year(curdate())
where (ClientOrganization = Org or Org='All')
and (Product = Pro or Pro = 'All')
AND LatestClosed between StartDate and EndDate
GROUP BY ClientOrganization, Product, Month, week
) alias
GROUP BY ClientOrganization, Product, Month, week
ORDER BY ClientOrganization, Product, Month, week;
I want to show it like the format shown above ..
Please help.
Regards.