是否可以在CASE中使用count,這裏是我的查詢。給我一個錯誤#1111使用COUNT的Mysql insde CASE
SELECT t1.id,t1.name,t1.date_entered,t1.date_modified, t1.adresse,t1.adresse_state,t1.adresse_city,t1.adresse_postalcode,t1.hausnummer,t1.center_lat,t1.center_long, t3.name as street_name,t3.strasse,t3.primaerstr
FROM hi_haus as t1
LEFT JOIN hi_haus_hi_strasse as t2 ON (t2.hi_haus_id = t1.id)
LEFT JOIN hi_strasse as t3 ON (t3.id = t2.hi_strasse_id)
WHERE t1.adresse !='' AND t1.adresse IS NOT NULL AND t1.adresse NOT LIKE '%bau%' AND t1.id IN ('58e722d6-44f5-4e24-8861-5cd4a6f07cbc','4d0a79ee-decf-49b1-8b4b-a912b278ffec')
AND t3.primaerstr =
CASE
WHEN count(t1.id) > '1' THEN t3.primaerstr='0'
ELSE
t3.primaerstr = '1'
END
GROUP BY t1.id
我需要做的是讓primaerstr「0」,如果ID被重複多次。
您只能選擇分組的那些列。在這種情況下,你是由t1.id分組,並選擇t1.name,t1.date等 –
我也選擇t1.id,查詢如果我不使用CASE,並具體使用計數的情況下 –
無論內容如何,您是基於連接還是正好計算表? – maSTAShuFu