AnalysisException:select 列表不支持子查询

AnalysisException: subqueries are not supported in the select list

我在使用以下查询时收到标题中显示的错误代码。我正在尝试查询两个表以查找有听力问题的患者总数以及接受过某种扫描(MR、SC、CT)的有听力问题患者的总数。

SELECT (
        SELECT COUNT(*)
        FROM hearing_evaluation 
        where severity_of_hearing_loss <> 'Normal'
        AND severity_of_hearing_loss <> 'insufficient data'
    ) AS patients_with_hearing_loss
    , AVG(number_of_scans) AS avg_number_of_scans
FROM (
    SELECT patient_id, COUNT(*) AS number_of_scans
    from imaging
    where patient_id IN (
        SELECT patient_id
        from hearing_evaluation
        where severity_of_hearing_loss <> 'Normal'
        and severity_of_hearing_loss <> 'insufficient data'
    )
    AND modality IN ('CT','MR','SC') 
    GROUP BY patient_id
) AS scans

如有任何帮助,我们将不胜感激。

我试过了,请参考下面的内容 SQL - 这将在 impala 中起作用。我能看到的唯一问题是,如果 hearing_evaluation 有多个给定患者 ID 的患者 ID,您需要删除重复数据。
可能存在图像中不存在患者 ID 的情况 table - 在这种情况下,您需要应用 RIGHT JOIN。

SELECT COUNT(patient_id) AS patients_with_hearing_loss , AVG(rs.number_of_scans) AS avg_number_of_scans FROM ( SELECT i.patient_id patient_id, COUNT(*) AS number_of_scans from imaging i ,hearing_evaluation h where i. patient_id = h.patient_id and h.severity_of_hearing_loss <> 'Normal' and h.severity_of_hearing_loss <> 'insufficient data' AND modality IN ('CT','MR','SC') GROUP BY i.patient_id ) rs