- HTML code
数据如下,第一行是列名。以第一条记录解释数据,在GD省GZ市的DuYun销售员一月份(Jan)品牌FA销售的销量是1200,在二月份(Feb)品牌FA的销售量是1800。Province city brand contact sale sale_monthGD GZ FA DuYun 1200 JanZJ HZ FB DuanT 1300 JanFJ FZ FC DeMa 1500 JanGD GZ FA DuYun 1800 FebZJ HZ FB DuanT 1900 FebFJ FZ FC DeMa 2000 Feb现在要做出如下的统计表格,分别统计每个销售人员的销售情况。Province city brand contact Jan FebGD GZ FA DuYun 1200 1800ZJ HZ FB DuanT 1300 1900FJ FZ FC DeMa 1500 2000
不知道这条语句该怎样写?
请诸位达人指教~~~~~小分送上~~~
------解决方案--------------------------------------------------------
SELECT Province,city,brand,SUM(case when sale_month
='jan' then sale else 0) as jsn ,SUM(case when sale_month
='feb' then sale else 0) as feb
FROM TT GROUP BY Province,city,brand
动态用SP生成SQL语句
------解决方案--------------------------------------------------------
- SQL code
select Province,city,brand,contact, sum(case sale_month when 'Jan' then sale end) as Jan, sum(case sale_month when 'Feb' then sale end) as Febfrom 数据如下group by Province,city,brand,contact