我試圖獲得5列,第一列是評估單元(EU),但在接下來的4列中,我要計算有多少家庭(不同的INSTANCE_ID_HOUSE)符合特定標準,但數據由居民儲存。這裏有4個查詢我使用的(我基本上只是想將它們組合成一個查詢):在GROUP BY級別使用「CASE」命令
SELECT EU, COUNT(DISTINCT INSTANCE_ID_HOUSE) FROM SENEGAL_CLEAN
WHERE CLUSTER_COMPLETE>0
GROUP BY EU
ORDER BY EU ASC
SELECT COUNT(DISTINCT INSTANCE_ID_HOUSE) FROM SENEGAL_CLEAN
WHERE CLUSTER_COMPLETE>0 AND (W1_DRINK_SOURCE=1 OR W1_DRINK_SOURCE=4)
GROUP BY EU
ORDER BY EU ASC
SELECT COUNT(DISTINCT INSTANCE_ID_HOUSE) FROM SENEGAL_CLEAN
WHERE CLUSTER_COMPLETE>0 AND (W2_GET_DRINK_WATER=1 OR W2_GET_DRINK_WATER=2)
GROUP BY EU
ORDER BY EU ASC
SELECT COUNT(DISTINCT INSTANCE_ID_HOUSE) FROM SENEGAL_CLEAN
WHERE CLUSTER_COMPLETE>0 AND (S2_SEE_LATRINE=1 OR S2_SEE_LATRINE=2)
GROUP BY EU
ORDER BY EU ASC
我得到了以下錯誤信息:#1052 - 在字段列表列「EU」是不明確的(我想弄明白,但你可能會更快) – beck777
我編輯了我的答案,注意查詢的第一行 – RezaRahmati
#1054 - 在'子句' – beck777