错误979:不是GROUP BY表达式

时间:2018-04-27 17:16:37

标签: sql oracle-sqldeveloper

尝试返回最后联系日期时出错

SELECT CDC.pat_id, MAX(SOC.contact_date), 
FROM hb61.cdcsaar_patients CDC
JOIN clarity.social_hx SOC ON CDC.pat_id=SOC.pat_id
LEFT OUTER JOIN clarity.smoking_cess_hx CESS ON CDC.pat_id=CESS.pat_id
LEFT OUTER JOIN clarity.social_hx_alc_use ALC on CDC.pat_id=ALC.pat_id
GROUP BY SOC.contact_date
;

2 个答案:

答案 0 :(得分:1)

您需要将所选列(在本例中为 CDC.pat_id )放在 GROUP BY 子句中,而不是将您应用于聚合功能

SELECT
  CDC.pat_id,
  MAX(SOC.contact_date)
FROM
  hb61.cdcsaar_patients CDC
  JOIN clarity.social_hx SOC ON CDC.pat_id = SOC.pat_id
  LEFT OUTER JOIN clarity.smoking_cess_hx CESS ON CDC.pat_id = CESS.pat_id
  LEFT OUTER JOIN clarity.social_hx_alc_use ALC on CDC.pat_id = ALC.pat_id
GROUP BY
  CDC.pat_id;

答案 1 :(得分:0)

您需要将任何的列应用聚合函数放入GROUP BY子句(在本例中为CDC.pat_id,而不是SOC.contact_date)。