好的,尝试不同的选项非常沮丧,需要一些建议。
我试图创建一种ROLLUP
,CUBE
查询,JET-SQl
除了字段的正确排序外,一切都按预期工作DATE
。
SELECT
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) AS [MNTH],
P.[WORK TYPE],
P.[CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
format(count (p.[work type])/(select count (p.[work type]) from p),'0.00%') as [Percentage Vol],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
GROUP BY
[WORK TYPE],
P.[CASE TYPE],
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY'))
ORDER BY 1
UNION
SELECT
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) & ' TOTAL' AS [MNTH],
'' AS [WORK TYPE],
'' AS [CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
format(count (p.[work type])/(select count (p.[work type]) from p),'0.00%') as [Percentage Vol],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
GROUP BY
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) & ' TOTAL'
ORDER BY 1
UNION
SELECT
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) AS [MNTH],
[WORK TYPE] & ' TOTAL' AS [WORK TYPE1],
'' AS [CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
format(count (p.[work type])/(select count (p.[work type]) from p),'0.00%') as [Percentage Vol],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
GROUP BY
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) ,
[WORK TYPE] &' TOTAL'
ORDER BY 1
UNION SELECT
'Z-TOTAL-Z' AS [MNTH],
'' AS [WORK TYPE1],
'' AS [CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
format(count (p.[work type])/(select count (p.[work type]) from p),'0.00%') as [Percentage Vol],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
ORDER BY 1
输出的一部分是
╔═════════════════╦═════════════════════════╦═══════════════════════╦════════════╦═════════════╦════════════════╦══════════════╗
║ MNTH ║ WORK TYPE ║ CASE TYPE ║ TOTAL TIME ║ TOTAL COUNT ║ Percentage Vol ║ AVERAGE TIME ║
╠═════════════════╬═════════════════════════╬═══════════════════════╬════════════╬═════════════╬════════════════╬══════════════╣
║ 1/6/2014 ║ Query ║ Deficit_on_SFS ║ 00:18:55 ║ 1 ║ 0.37% ║ 00:18:55 ║
║ 1/6/2014 ║ Query ║ Rental_Income ║ 00:00:24 ║ 1 ║ 0.37% ║ 00:00:24 ║
║ 1/6/2014 ║ Query ║ Support_from_Family ║ 00:00:30 ║ 1 ║ 0.37% ║ 00:00:30 ║
║ 1/6/2014 ║ Query TOTAL ║ ║ 00:19:49 ║ 3 ║ 1.10% ║ 00:06:36 ║
║ 1/6/2014 ║ System_Downtime ║ Downtime ║ 00:00:18 ║ 2 ║ 0.74% ║ 00:00:09 ║
║ 1/6/2014 ║ System_Downtime TOTAL ║ ║ 00:00:18 ║ 2 ║ 0.74% ║ 00:00:09 ║
║ 1/6/2014 TOTAL ║ ║ ║ 00:26:48 ║ 21 ║ 7.72% ║ 00:01:17 ║
║ 12/6/2014 ║ Decline_to_Branch ║ Duplicate ║ 00:02:01 ║ 5 ║ 1.84% ║ 00:00:24 ║
║ 12/6/2014 ║ Decline_to_Branch ║ Incorrect_Docs ║ 00:01:47 ║ 3 ║ 1.10% ║ 00:00:36 ║
║ 12/6/2014 ║ Decline_to_Branch ║ Missing_Docs ║ 00:01:35 ║ 4 ║ 1.47% ║ 00:00:24 ║
║ 12/6/2014 ║ Decline_to_Branch ║ Not_for_ASU ║ 00:00:23 ║ 1 ║ 0.37% ║ 00:00:23 ║
║ 12/6/2014 ║ Decline_to_Branch TOTAL ║ ║ 00:05:46 ║ 13 ║ 4.78% ║ 00:00:27 ║
║ 12/6/2014 TOTAL ║ ║ ║ 00:05:46 ║ 13 ║ 4.78% ║ 00:00:27 ║
║ 2/6/2014 ║ Adhoc_Work ║ Non_ASU_Related_Adhoc ║ 00:00:24 ║ 2 ║ 0.74% ║ 00:00:12 ║
║ 2/6/2014 ║ Adhoc_Work TOTAL ║ ║ 00:00:24 ║ 2 ║ 0.74% ║ 00:00:12 ║
║ 2/6/2014 ║ Assessment ║ HL ║ 00:00:40 ║ 2 ║ 0.74% ║ 00:00:20 ║
║ 2/6/2014 ║ Assessment ║ HL_and_BTL ║ 00:01:20 ║ 2 ║ 0.74% ║ 00:00:40 ║
║ 2/6/2014 ║ Assessment TOTAL ║ ║ 00:02:00 ║ 4 ║ 1.47% ║ 00:00:30 ║
║ 2/6/2014 ║ Break ║ Lunch ║ 00:03:24 ║ 6 ║ 2.21% ║ 00:00:34 ║
║ 2/6/2014 ║ Break TOTAL ║ ║ 00:03:24 ║ 6 ║ 2.21% ║ 00:00:34 ║
╚═════════════════╩═════════════════════════╩═══════════════════════╩════════════╩═════════════╩════════════════╩══════════════╝
是的,ORDERBY
它没有按预期工作。
谁能建议如何正确设置
更新1
我尝试用 替换该
CDATE
位DATEVALUE
,但这也不起作用我试过使用 order by as
DATEVALUE(P.[START TIME]) & ' TOTAL'
,这也没有帮助
更新2
我别无选择,只能做这样的事情,你不是很高兴,但由于时间限制想继续这样做,如果有人有更好的方法建议
SELECT
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) AS [MNTH],
P.[WORK TYPE],
P.[CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
FORMAT(COUNT (P.[WORK TYPE])/(SELECT COUNT (P.[WORK TYPE]) FROM P),'0.00%') AS [PERCENTAGE VOL],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
GROUP BY
[WORK TYPE],
P.[CASE TYPE],
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY'))
ORDER BY 1,2
UNION
SELECT
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) AS [MNTH],
'Z-TOTAL-Z FOR '& CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) AS [WORK TYPE],
'' AS [CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
FORMAT(COUNT (P.[WORK TYPE])/(SELECT COUNT (P.[WORK TYPE]) FROM P),'0.00%') AS [PERCENTAGE VOL],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
GROUP BY
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY'))
UNION
SELECT
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) AS [MNTH],
[WORK TYPE] & ' TOTAL' AS [WORK TYPE1],
'' AS [CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
FORMAT(COUNT (P.[WORK TYPE])/(SELECT COUNT (P.[WORK TYPE]) FROM P),'0.00%') AS [PERCENTAGE VOL],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)
GROUP BY
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) ,
[WORK TYPE] &' TOTAL'
UNION
SELECT
NULL AS [MNTH],
'ZZ-GRAND TOTAL-ZZ' AS [WORK TYPE1],
'' AS [CASE TYPE],
FORMAT(SUM(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [TOTAL TIME],
COUNT([ID]) AS [TOTAL COUNT],
FORMAT(COUNT (P.[WORK TYPE])/(SELECT COUNT (P.[WORK TYPE]) FROM P),'0.00%') AS [PERCENTAGE VOL],
FORMAT(AVG(DATEDIFF("S",[START TIME],[END TIME]))/86400,"HH:NN:SS") AS [AVERAGE TIME]
FROM P
WHERE
SWITCH
(
FORMS!DASHBOARD!CUSER='ALL'
,
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
,
FORMS!DASHBOARD!CUSER<>'ALL'
,
P.[USER]=FORMS!DASHBOARD!CUSER AND
CDATE(FORMAT(P.[START TIME],'DD/MM/YYYY')) BETWEEN CDATE(FORMAT(FORMS!DASHBOARD!CSTART,'DD/MM/YYYY'))
AND
CDATE(FORMAT(FORMS!DASHBOARD!CEND,'DD/MM/YYYY'))
)