Sale表中横列值转换成竖列显示。
SELECT EmployeeID,
max(case SaleDate when '2007-01-01' then amount else null end) as jan,
max(case SaleDate when '2007-02-01' then amount else null end) as feb,
max(case SaleDate when '2007-03-01' then amount else null end) as mar,
max(case SaleDate when '2007-04-01' then amount else null end) as apr,
max(case SaleDate when '2007-05-01' then amount else null end) as may,
max(case SaleDate when '2007-06-01' then amount else null end) as jun,
max(case SaleDate when '2007-07-01' then amount else null end) as aug
from Liaohaibing.SALE
group by Liaohaibing.SALE.EMPLOYEEID;
max(case SaleDate when '2007-01-01' then amount else null end) as jan,
max(case SaleDate when '2007-02-01' then amount else null end) as feb,
max(case SaleDate when '2007-03-01' then amount else null end) as mar,
max(case SaleDate when '2007-04-01' then amount else null end) as apr,
max(case SaleDate when '2007-05-01' then amount else null end) as may,
max(case SaleDate when '2007-06-01' then amount else null end) as jun,
max(case SaleDate when '2007-07-01' then amount else null end) as aug
from Liaohaibing.SALE
group by Liaohaibing.SALE.EMPLOYEEID;
EmployeID | jan | feb | mar | apr | may | jun | aug |
1 | 1005 | 1452 | 524 | 345 | 567 | 587 | 524 |
2 | 1008 | 5224 | 524 | 345 | 567 | 578 | 552 |
3 | 1007 | 5424 | 524 | 345 | 567 | 698 | 5224 |
4 | 1005 | 5524 | 524 | 345 | 567 | 895 | 54 |
5 | 1009 | 5224 | 524 | 345 | 567 | 698 | 554 |
6 | 1008 | 524 | 524 | 345 | 567 | 2452 | 5221 |
7 | 1006 | 524 | 524 | 345 | 567 | 354 | 4 |
8 | 1005 | 524 | 524 | 345 | 567 | 243 | 5 |
9 | 1005 | 524 | 524 | 345 | 567 | 2546 | 556 |
10 | 100 | 524 | 524 | 345 | 567 | 5244 | 254 |
有一个 Sale 表里面放着每个销售员每个月的销售情况
现在要把这一年,按月分进行显示出每个销售员得销售情况。
上面这种法子可以实现。