У меня есть запрос, который берет индивидуальные данные о сотруднике, затем итоговую сумму в соответствии с местоположением и, наконец, общую сумму. В первом утверждении выбора мне нужно взять максимум (столбец 9), но в объединении мне нужно взять сумму column9). Я получаю сообщение об ошибке «Несоответствие типов данных». Следующий запрос:
SELECT COLUMN1 AS LASTNAME,
COLUMN2 AS FIRSTNAME,
COLUMN3 AS LOCATION,
SUM(COLUMN4) AS ACTIVITYNM1,
SUM(COLUMN5) AS ACTIVITYNM2,
SUM(COLUMN6) AS ACTIVITYNM3,
SUM(COLUMN7) AS ACTIVITYNM4,
SUM(COLUMN8) AS ACTIVITYNM5,
MAX(COLUMN9) AS REG_HRS,
MAX(COLUMN10) AS OT_HRS,
MAX(COLUMN11) AS TOTAL_HRS,
SUM(COLUMN12) AS PRODUCTIVITY_PERCENTAGE,
COLUMN13 AS FULL_LOCATION
FROM TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE))
GROUP BY COLUMN1, COLUMN2, COLUMN3, COLUMN13
UNION
SELECT NULL,
NULL,
CONCAT(SUBSTR(COLUMN3,3,3),' Total') AS LOCATION,
SUM(COLUMN4) AS ACTIVITYNM1,
SUM(COLUMN5) AS ACTIVITYNM2,
SUM(COLUMN6) AS ACTIVITYNM3,
SUM(COLUMN7) AS ACTI,
VITYNM4,
SUM(COLUMN8) AS ACTIVITYNM5,
SUM(COLUMN9) AS REG_HRS,
SUM(COLUMN10) AS OT_HRS,
SUM(COLUMN11) AS TOTAL_HRS,
(SUM(COLUMN12)/COUNT(DISTINCT(COLUMN1))) AS PRODUCTIVITY_PERCENTAGE,
COLUMN13 AS FULL_LOCATION
FROM TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE))
GROUP BY COLUMN3, COLUMN13
=============================================== ========================================
Привет. Большое спасибо за все ответы. Я получил решение. Я использую подзапрос во втором объединении. Я вставляю код здесь.
SELECT
COLUMN1 AS EMPID,
COLUMN2 AS FIRSTNAME,
COLUMN3 AS LASTNAME,
COLUMN4 AS LOCATION,
SUM(COLUMN5) AS ACTIVITYNM1,
SUM(COLUMN6) AS ACTIVITYNM2,
SUM(COLUMN7) AS ACTIVITYNM3,
SUM(COLUMN8) AS ACTIVITYNM4,
SUM(COLUMN9) AS ACTIVITYNM5,
MIN(COLUMN10) AS EVENTDATE,
TO_NUMBER(COLUMN11) AS REG_HRS,
TO_NUMBER(COLUMN12) AS OT_HRS,
TO_NUMBER(COLUMN13) AS TOTAL_HRS,
SUM(COLUMN14) AS PRODUCTIVITY_PERCENTAGE
FROM
TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE))
GROUP BY
COLUMN1,
COLUMN2,
COLUMN3,
COLUMN4,
COLUMN11,
COLUMN12,
COLUMN13
UNION
SELECT
NULL AS EMPID,
NULL AS LASTNAME,
NULL AS FIRSTNAME,
SUBSTR(INNER_REC.LOCATION,2,5) AS LOCATION,
SUM(INNER_REC.ACTIVITYNM1) AS ACTIVITYNM1,
SUM(INNER_REC.ACTIVITYNM2) AS ACTIVITYNM2,
SUM(INNER_REC.ACTIVITYNM3) AS ACTIVITYNM3,
SUM(INNER_REC.ACTIVITYNM4) AS ACTIVITYNM4,
SUM(INNER_REC.ACTIVITYNM5) AS ACTIVITYNM5,
MIN(INNER_REC.EVENTDATE) AS EVENTDATE,
SUM(INNER_REC.REG_HRS) AS REG_HRS,
SUM(INNER_REC.OT_HRS) AS OT_HRS,
SUM(INNER_REC.TOTAL_HRS) AS TOTAL_HRS,
SUM(INNER_REC.PRODUCTIVITY_PERCENTAGE) AS PRODUCTIVITY_PERCENTAGE
FROM
(
SELECT
COLUMN1 AS EMPID,
NULL AS LASTNAME,
NULL AS FIRSTNAME,
COLUMN4 AS LOCATION,
SUM(COLUMN5) AS ACTIVITYNM1,
SUM(COLUMN6) AS ACTIVITYNM2,
SUM(COLUMN7) AS ACTIVITYNM3,
SUM(COLUMN8) AS ACTIVITYNM4,
SUM(COLUMN9) AS ACTIVITYNM5,
MIN(COLUMN10) AS EVENTDATE,
SUM(TO_NUMBER(COLUMN11))/(SELECT COUNT(1) FROM TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE)) AB WHERE AB.COLUMN4 =
CD.COLUMN4 AND AB.COLUMN1 = CD.COLUMN1) AS REG_HRS,
SUM(TO_NUMBER(COLUMN12))/(SELECT COUNT(1) FROM TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE)) AB WHERE AB.COLUMN4 =
CD.COLUMN4 AND AB.COLUMN1 = CD.COLUMN1) AS OT_HRS,
SUM(TO_NUMBER(COLUMN13))/(SELECT COUNT(1) FROM TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE)) AB WHERE AB.COLUMN4 =
CD.COLUMN4 AND AB.COLUMN1 = CD.COLUMN1) AS TOTAL_HRS,
SUM(COLUMN14) AS PRODUCTIVITY_PERCENTAGE
FROM
TABLE(ACTY_COL(V_STARTDATE,V_ENDDATE)) CD
GROUP BY
COLUMN4,
COLUMN1
) INNER_REC
GROUP BY
INNER_REC.LOCATION