以下是访问查询:
TRANSFORM Sum(EMPL_VAL_AMT) AS SumOfEMPL_VAL_AMT
SELECT ORG_TOT_LOWEST_LEVEL_ID,
ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD,
EMPL_VER_DIM_MBR_CD,
ORG_TOT_ALLOC_POOL_CD
FROM EMPL_FCST
GROUP BY ORG_TOT_LOWEST_LEVEL_ID,
ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD,
EMPL_VER_DIM_MBR_CD,
ORG_TOT_ALLOC_POOL_CD
ORDER BY FDATE([EMPL_FMONTH] & "/" & [EMPL_FYEAR])
PIVOT FDATE([EMPL_FMONTH] & "/" & [EMPL_FYEAR]);
以下是我在Oracle 12cr2中的尝试:
SELECT ORG_TOT_LOWEST_LEVEL_ID, ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD, EMPL_VER_DIM_MBR_CD, ORG_TOT_ALLOC_POOL_CD
FROM EMPL_FCST
GROUP BY ORG_TOT_LOWEST_LEVEL_ID, ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD, EMPL_VER_DIM_MBR_CD, ORG_TOT_ALLOC_POOL_CD
ORDER BY EMPL_FMONTH || "/" || EMPL_FYEAR AS FDATE
PIVOT
(
SUM(EMPL_VAL_AMT) IN EMPL_FMONTH || "/" || EMPL_FYEAR AS FDATE
)
我正在尝试创建一个轴,它将两个字段EMPL_FMONTH
和EMPLY_FYEAR
组合为FDATE
,作为EMP_VAL_AMT
之和的列标题。在每个时间段内,最重要的是1/18 | 2/18 | 3/18
的总和为EMPL_VAL_AMT
。
以下是我尝试运行代码的错误:
Error starting at line : 1 in command -
SELECT ORG_TOT_LOWEST_LEVEL_ID, ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD, EMPL_VER_DIM_MBR_CD, ORG_TOT_ALLOC_POOL_CD
FROM EMPL_FCST
GROUP BY ORG_TOT_LOWEST_LEVEL_ID, ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD, EMPL_VER_DIM_MBR_CD, ORG_TOT_ALLOC_POOL_CD
ORDER BY EMPL_FMONTH || "/" || EMPL_FYEAR AS FDATE
PIVOT
(
SUM(EMPL_VAL_AMT) IN EMPL_FMONTH || "/" || EMPL_FYEAR AS FDATE
)
Error at Command Line : 4 Column : 43
Error report -
SQL Error: ORA-00933: SQL command not properly ended
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
我一直在尝试使用括号,括号和排序的各种组合来清理语法。除此之外,我甚至不确定我是否正确接近逻辑。任何帮助将不胜感激。谢谢!
编辑:
好的,我使用每个人对此的反馈重新编写了查询并成功运行:
SELECT * FROM
(
SELECT ORG_TOT_LOWEST_LEVEL_ID, ORG_TOT_ACCTG_DEPT_ID,
EMPL_SCENR_DIM_MBR_CD, EMPL_VER_DIM_MBR_CD, ORG_TOT_ALLOC_POOL_CD,
EMPL_VAL_AMT, EMPL_FMONTH, EMPL_FYEAR
FROM EMPL_FCST
)
PIVOT
(
SUM(EMPL_VAL_AMT)
FOR EMPL_FYEAR
IN (2018, 2019)
)
有没有办法将FYEAR
列和FMONTH
列合并为一个看起来像MM / YYYY的列,然后在枢轴子句中将其用作我的FOR?