|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
呵呵,这么大的工作量……
TRANSFORM Min([%$##@_Alias].类别) AS 类别OfMin
SELECT [%$##@_Alias].分类
FROM [SELECT T1.分类,T1.日期,IIF(COUNT(T2.序列)<5,COUNT(T2.序列),5) AS 类别 FROM
(SELECT 日期,分类,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列 FROM
(SELECT DISTINCT 日期 FROM 开卷)A1,
(SELECT DISTINCT 分类 FROM 开卷)A2)T1
LEFT JOIN
(SELECT 分类,日期,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列
FROM 开卷)T2
ON T1.分类=T2.分类 AND T1.序列>=T2.序列
GROUP BY T1.分类,T1.日期
UNION ALL
SELECT "合计",日期,SUM(类别) FROM
(SELECT T1.日期,IIF(COUNT(T2.序列)<5,COUNT(T2.序列),5) AS 类别 FROM
(SELECT 日期,分类,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列 FROM
(SELECT DISTINCT 日期 FROM 开卷)A1,
(SELECT DISTINCT 分类 FROM 开卷)A2)T1
LEFT JOIN
(SELECT 分类,日期,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列
FROM 开卷)T2
ON T1.分类=T2.分类 AND T1.序列>=T2.序列
GROUP BY T1.分类,T1.日期)
GROUP BY 日期
UNION ALL
SELECT "总计",P1.日期,MIN(P1.值1-NZ(P2.值2)) FROM
(SELECT 序列,日期,SUM(类别) AS 值1 FROM
(SELECT T1.日期,T1.序列,IIF(COUNT(T2.序列)<5,COUNT(T2.序列),5) AS 类别 FROM
(SELECT 日期,分类,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列 FROM
(SELECT DISTINCT 日期 FROM 开卷)A1,
(SELECT DISTINCT 分类 FROM 开卷)A2)T1
LEFT JOIN
(SELECT 分类,日期,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列
FROM 开卷)T2
ON T1.分类=T2.分类 AND T1.序列>=T2.序列
GROUP BY T1.分类,T1.日期,T1.序列)
GROUP BY 日期,序列)P1
LEFT JOIN
(SELECT 序列,日期,SUM(类别) AS 值2 FROM
(SELECT T1.日期,T1.序列,IIF(COUNT(T2.序列)<5,COUNT(T2.序列),5) AS 类别 FROM
(SELECT 日期,分类,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列 FROM
(SELECT DISTINCT 日期 FROM 开卷)A1,
(SELECT DISTINCT 分类 FROM 开卷)A2)T1
LEFT JOIN
(SELECT 分类,日期,CDATE(IIF(ISDATE(日期),日期,INSTR("期初4月第三周",日期))) AS 序列
FROM 开卷)T2
ON T1.分类=T2.分类 AND T1.序列>=T2.序列
GROUP BY T1.分类,T1.日期,T1.序列)
GROUP BY 日期,序列)P2
ON P1.序列>P2.序列
GROUP BY P1.序列,P1.日期]. AS [%$##@_Alias]
GROUP BY [%$##@_Alias].分类
PIVOT [%$##@_Alias].日期;
|
|