我正在努力做一些事情。第一个子查询是总扫描计数。第二个子查询在60分钟内扫描计数。提前抱歉被压缩了。两者分开时都能正常运行。
我得到一个“当没有用EXISTS引入子查询时,在选择列表中只能指定一个表达式”错误在第12和22行我不熟悉存在。
SELECT
MONTH(F_IP_HSP_SUM_MED_ADMIN.SCHEDULED_DATETIME) AS MONTH
,V_MAR_BARCODE_COMPLIANCE.DEPARTMENT_NAME AS UNIT
,(SELECT DISTINCT
MONTH(F_IP_HSP_SUM_MED_ADMIN.SCHEDULED_DATETIME) AS MONTH
,V_MAR_BARCODE_COMPLIANCE.DEPARTMENT_NAME AS UNIT
,count(med_scanned_bool)
FROM F_IP_HSP_SUM_MED_ADMIN
INNER JOIN V_MAR_BARCODE_COMPLIANCE ON F_IP_HSP_SUM_MED_ADMIN.ORDER_MED_ID=V_MAR_BARCODE_COMPLIANCE.ORDER_MED_ID AND LINE=MAR_LINE
WHERE MED_SCANNED_BOOL=1
GROUP BY MONTH(SCHEDULED_DATETIME), V_MAR_BARCODE_COMPLIANCE.DEPARTMENT_NAME
) AS SCANNED_D
,(SELECT DISTINCT
MONTH(F_IP_HSP_SUM_MED_ADMIN.SCHEDULED_DATETIME) AS MONTH
,V_MAR_BARCODE_COMPLIANCE.DEPARTMENT_NAME AS UNIT
,count(med_scanned_bool) AS SCANNED_N
FROM F_IP_HSP_SUM_MED_ADMIN
INNER JOIN V_MAR_BARCODE_COMPLIANCE ON F_IP_HSP_SUM_MED_ADMIN.ORDER_MED_ID=V_MAR_BARCODE_COMPLIANCE.ORDER_MED_ID AND LINE=MAR_LINE
WHERE MED_SCANNED_BOOL=1
AND SECONDS_AFTER_SCHEDULED<'3600' --Within 60 Minute Window
GROUP BY MONTH(SCHEDULED_DATETIME), V_MAR_BARCODE_COMPLIANCE.DEPARTMENT_NAME
)AS SCANNED_N
FROM F_IP_HSP_SUM_MED_ADMIN
INNER JOIN V_MAR_BARCODE_COMPLIANCE ON F_IP_HSP_SUM_MED_ADMIN.ORDER_MED_ID=V_MAR_BARCODE_COMPLIANCE.ORDER_MED_ID AND LINE=MAR_LINE
答案 0 :(得分:0)
(SELECT DISTINCT
MONTH(F_IP_HSP_SUM_MED_ADMIN.SCHEDULED_DATETIME) AS MONTH,
V_MAR_BARCODE_COMPLIANCE.DEPARTMENT_NAME AS UNIT,
count(med_scanned_bool)
...) AS SCANNED_D
在查询的列选择部分中,您只能有返回一个列的子选择,而不是3.
如果您正在使用具有公用表表达式支持的数据库,则可以通过加入CTE来替换多列子选择。