我无法在Toad中运行以下查询。
我收到错误ORA-32033: unsupported column alias
。
WITH
sample_data( month, day ) AS (
SELECT TO_CHAR(TO_DATE(X,'DD-MM-YY'),'MON') AS month,
TO_CHAR(TO_DATE(X,'DD-MM-YY'),'DD') AS day
FROM (SELECT CASE WHEN TO_CHAR(TO_DATE('01-05-2015','DD-MM-YY')+(ROWNUM-1),'DY') = 'FRI'
THEN TO_CHAR(TO_DATE('01-05-2015','DD-MM-YY')+(ROWNUM-1),'DD-MM-YY')
ELSE NULL END AS X
FROM all_objects
WHERE ROWNUM < (select (to_date ('01-05-16','dd-MM-yyyy')
- to_date('01-05-15','dd-MM-yyyy') + 1)
from dual)
)
WHERE X IS NOT NULL;
),
ordered_dates( month, day, seq_no ) AS (
SELECT month,
day,
ROW_NUMBER() OVER ( PARTITION BY month ORDER BY day )
FROM sample_data
)
SELECT MAX( CASE WHEN month = 'Jan' AND seq_no = 1 THEN day END ) AS "Jan",
MAX( CASE WHEN month = 'Jan' AND seq_no = 2 THEN day END ) AS "Jan",
MAX( CASE WHEN month = 'Jan' AND seq_no = 3 THEN day END ) AS "Jan",
MAX( CASE WHEN month = 'Feb' AND seq_no = 1 THEN day END ) AS "Feb",
MAX( CASE WHEN month = 'Feb' AND seq_no = 2 THEN day END ) AS "Feb",
MAX( CASE WHEN month = 'Feb' AND seq_no = 3 THEN day END ) AS "Feb"
FROM ordered_dates;
我做错了什么?
答案 0 :(得分:2)
基于your previous question title,这个问题似乎是一个扩展,你使用的是Oracle 10g。列别名不是Oracle 10g中WITH
子句语法的一部分。 syntax diagram from 10gR2:
别名是递归子查询因子分解所必需的 - 也在11gR2中添加 - 否则是可选的。
对于10g,您需要将列作为子查询的一部分进行别名,除了seq_no
之外,您已经做了一些冗余,但是您还需要从WITH ... AS
部分删除别名:< / p>
WITH sample_data AS (
SELECT TO_CHAR(TO_DATE(X,'DD-MM-YY'),'MON') AS month,
TO_CHAR(TO_DATE(X,'DD-MM-YY'),'DD') AS day
FROM
...
),
ordered_dates AS (
SELECT month,
day,
ROW_NUMBER() OVER ( PARTITION BY month ORDER BY day ) AS seq_no
FROM sample_data
)
...