|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
没注意到楼主的要求是产品在前,客户在后,上面搞反了,查询语句改为:
SELECT [A##1].产品, [A##1].客戶, Sum(IIf([A##1].A="1月",[A##1].S,0)) AS 一月数量, Sum(IIf([A##1].A="1月",[A##1].L,0)) AS 一月利润, Sum(IIf([A##1].A="2月",[A##1].S,0)) AS 二月数量, Sum(IIf([A##1].A="2月",[A##1].L,0)) AS 二月利润, Sum(IIf([A##1].A="3月",[A##1].S,0)) AS 三月数量, Sum(IIf([A##1].A="3月",[A##1].L,0)) AS 三月利润, Sum(IIf([A##1].A="4月",[A##1].S,0)) AS 四月数量, Sum(IIf([A##1].A="4月",[A##1].L,0)) AS 四月利润, Sum(IIf([A##1].A="5月",[A##1].S,0)) AS 五月数量, Sum(IIf([A##1].A="5月",[A##1].L,0)) AS 五月利润, Sum(IIf([A##1].A="6月",[A##1].S,0)) AS 六月数量, Sum(IIf([A##1].A="6月",[A##1].L,0)) AS 六月利润, Sum(IIf([A##1].A="7月",[A##1].S,0)) AS 七月数量, Sum(IIf([A##1].A="7月",[A##1].L,0)) AS 七月利润, Sum(IIf([A##1].A="8月",[A##1].S,0)) AS 八月数量, Sum(IIf([A##1].A="8月",[A##1].L,0)) AS 八月利润, Sum(IIf([A##1].A="9月",[A##1].S,0)) AS 九月数量, Sum(IIf([A##1].A="9月",[A##1].L,0)) AS 九月利润, Sum(IIf([A##1].A="10月",[A##1].S,0)) AS 十月数量, Sum(IIf([A##1].A="10月",[A##1].L,0)) AS 十月利润, Sum(IIf([A##1].A="11月",[A##1].S,0)) AS 十一月数量, Sum(IIf([A##1].A="11月",[A##1].L,0)) AS 十一月利润, Sum(IIf([A##1].A="12月",[A##1].S,0)) AS 十二月数量, Sum(IIf([A##1].A="12月",[A##1].L,0)) AS 十二月利润
FROM (SELECT [資料表1].客戶, [資料表1].产品, Sum([資料表1].数量) AS S, Sum([資料表1].利润) AS L, Format([日期],"m\月") AS A
FROM [資料表1]
GROUP BY [資料表1].客戶, [資料表1].产品, Format([日期],"m\月")
) AS [A##1]
GROUP BY [A##1].客戶, [A##1].产品; |
|