我从此代码中收到错误“太多的值”。有人能告诉我我做错了吗?
SELECT (:START_DATE)|| ' TO '|| (:END_DATE) ACTIVITY_PERIOD,
EMP_NO,
DEPT,
EMP_NAME,
COUNT(*)"# OF VIOLATIONS",
(SELECT TO_CHAR(IN_TIME,'HH:MI AM') AS INTIME,
TO_CHAR(OUT_TIME,'HH:MI') AS OUTTIME
FROM INV.HR_ATTENDANCES A
WHERE TO_CHAR(IN_TIME,'HH:MI')=:IN_TIME
AND TO_CHAR(OUT_TIME,'HH:MI')=:OUT_TIME)
FROM INV.EMP_ACTIVITY_HISTORY_SHIFTS
WHERE (ATTENDANCE_DATE BETWEEN :START_DATE AND :END_DATE)
AND (TOTAL_OUT > 4 OR MINT > (case when to_char(attendance_date,'DAY')= 'FRIDAY' then 135 else 90 end))
GROUP BY TO_CHAR(ATTENDANCE_DATE,'MON-RRRR'),EMP_NO,EMP_NAME,ORG_ID,DEPT,SHIFT_ID
ORDER BY 5 DESC
答案 0 :(得分:2)
可能是因为下面的代码段问题。
(SELECT TO_CHAR(IN_TIME,'HH:MI AM') AS INTIME,
TO_CHAR(OUT_TIME,'HH:MI') AS OUTTIME
FROM INV.HR_ATTENDANCES A
WHERE TO_CHAR(IN_TIME,'HH:MI')=:IN_TIME
AND TO_CHAR(OUT_TIME,'HH:MI')=:OUT_TIME)
当某个子查询用作SELECT
列的一部分时,查询的输出应该恰好是1行,1列,以便查询的输出可以被视为整个查询结果中的列。
请检查以下
连接两列(例如:TO_CHAR(IN_TIME,'HH:MI AM') || 'IN '|| TO_CHAR(OUT_TIME,'HH:MI') ||' OUT' AS IN_OUTTIME
)
或者
作为外部查询的一部分,您需要将它们作为2个单独的子查询
例如:SELECT ....,(sELECT TO_CHARIN_TIME..()...FROM inv.hr_attendances..) IN_TIME, (sELECT TO_CHAR(OUT_TIME...)...FROM inv.hr_attendances..) OUTTIME from ...
作为替代方案,您可以将整个子查询移至WITH
子句或将JOIN
移至主查询
例如:
WITH IN_OUT_TIME AS (
(SELECT TO_CHAR(IN_TIME,'HH:MI AM') AS INTIME,
TO_CHAR(OUT_TIME,'HH:MI') AS OUTTIME
FROM INV.HR_ATTENDANCES A
WHERE TO_CHAR(IN_TIME,'HH:MI')=:IN_TIME
AND TO_CHAR(OUT_TIME,'HH:MI')=:OUT_TIME))
SELECT (:START_DATE)|| ' TO '|| (:END_DATE) ACTIVITY_PERIOD,
EMP_NO,
DEPT,
EMP_NAME,
COUNT(*)"# OF VIOLATIONS",
IN_TIME,
OUT_TIME
FROM INV.EMP_ACTIVITY_HISTORY_SHIFTS , IN_OUT_TIME
WHERE (ATTENDANCE_DATE BETWEEN :START_DATE AND :END_DATE)
AND (TOTAL_OUT > 4
OR
MINT > (case when to_char(attendance_date,'DAY')= 'FRIDAY' then 135 else 90 end))`
另外,请注意,group by子句应包含SELECT
语句中的列,但作为组函数派生的列除外(例如:count(*)
)。请按要求重新访问您的小组。