0
我有以下查詢工作就像我想要它,除了我想返回一個僞(?)列計數的單位數每個屬性有內部匹配連接。其中p.team = u.team和u.deleted ='0000-00-00 00:00:00'和u.rates!='0'。我可以在相同的查詢中做到這一點嗎?MySQL - 計數內部聯接查詢
屬性有幾個單位。他們都附屬於「團隊」(認爲用戶名)。
SELECT DISTINCT p.title, p.state, p.city, p.regionID, p.team, p.type, p.lat, p.lng, p.url_title
FROM Properties AS p
INNER JOIN Units AS u ON p.team = u.team
INNER JOIN Rates AS r ON p.team = r.team
INNER JOIN Photos AS ph ON p.team = ph.team
AND p.public = '1'
AND u.rates != '0'
AND p.deleted = '0000-00-00 00:00:00'
AND u.deleted = '000-00-00 00:00:00'
AND r.deleted = '000-00-00 00:00:00'
AND ph.deleted = '000-00-00 00:00:00'
GROUP BY p.id
ORDER BY p.created ASC
COUNT(DISTINCT(u.id))訣竅。謝謝! – David 2012-07-19 18:25:39