尝试在hive中执行以下查询。抛出异常无法识别' SELECT' ' DISTINCT' '('在表达规范中。感谢任何帮助。
SELECT DISTINCT (FISCAL_QUARTER_START_DATE)
FROM TEST_STAGE.TEST_TABLE
WHERE FISCAL_YEAR_ID =
(SELECT FISCAL_YEAR_ID
FROM TEST_STAGE.TEST_TABLE
WHERE CALENDAR_DATE = FROM_UNIXTIME (UNIX_TIMESTAMP ()))
AND SUBSTR (FISCAL_QUARTER_NAME, 0, 2) =
(SELECT SUBSTR (FISCAL_QUARTER_NAME, 0, 2)
FROM TEST_STAGE.TEST_TABLE
WHERE CALENDAR_DATE = FROM_UNIXTIME (UNIX_TIMESTAMP ()))
由于
答案 0 :(得分:1)
使用适当的表别名和IN
子句代替=
进行子查询。
SELECT DISTINCT (t1.FISCAL_QUARTER_START_DATE)
FROM TEST_STAGE.TEST_TABLE t1
WHERE t1.FISCAL_YEAR_ID IN (
SELECT t2.FISCAL_YEAR_ID
FROM TEST_STAGE.TEST_TABLE t2
WHERE t2.CALENDAR_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP())
)
AND SUBSTR(t1.FISCAL_QUARTER_NAME, 0, 2) IN (
SELECT SUBSTR(t3.FISCAL_QUARTER_NAME, 0, 2)
FROM TEST_STAGE.TEST_TABLE t3
WHERE t3.CALENDAR_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP())
);
我认为您的查询是等效的,可以使用EXISTS
转换为单个子查询。
SELECT DISTINCT t1.FISCAL_QUARTER_START_DATE
FROM TEST_STAGE.TEST_TABLE t1
WHERE EXISTS (
SELECT 1
FROM TEST_STAGE.TEST_TABLE t2
WHERE SUBSTR(t1.FISCAL_QUARTER_NAME, 0, 2) = SUBSTR(t2.FISCAL_QUARTER_NAME, 0, 2)
AND t1.FISCAL_YEAR_ID = t2.FISCAL_YEAR_ID
AND t1.CALENDAR_DATE = FROM_UNIXTIME(UNIX_TIMESTAMP())
);