您好,我创建了以下查询,以按月为salesMen提取总订单。虽然这为我提供了一个销售员所需的数据,但我需要运行多个数据。我要完成的是一个查询,该查询针对多个不同的销售人员进行拉动,并按月份细分,月份为列名称(列动态到要拉动的月份)。如下所示。
SalesMen - 10-2017 - 11-2017 - 12-2017 - 01/2018
------------------------------------------------------------
Salesmen_1 Month_total(5) 15 300 100
Salesmen_2 100 948 821 684
当前代码:
select (case when region_code in ('123','124') then 'SalesMen_1' else 'N/A' end)SalesMen, to_char(DATE_ENTERED, 'MM-YYYY') as MM_YYYY, Count(ORder_NO) as Month_Total
from ORDERS
where
REGEXP_like (ORder_NO, '^W|^E')
and DATE_ENTERED between ADD_MONTHS(TO_DATE(TO_CHAR(ADD_MONTHS(SYSDATE, 2), 'YYYY') || '-01-01', 'YYYY-MM-DD'), -3) and TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM')|| '-01', 'YYYY-MM-DD') - 1
and region_code in ('123','124')
group by to_char(DATE_ENTERED, 'MM-YYYY'),(case when region_code in ('123','124') then 'SalesMen_1' else 'N/A' end)
order by to_char(DATE_ENTERED, 'MM-YYYY') desc