我有以下查询,它可以像我想要的那样工作,除了我想返回一个伪(?)列,该列是每个属性具有的与内部连接匹配的单元数的计数。其中 p.team = u.team 和 u.deleted = '0000-00-00 00:00:00' 和 u.rates != '0'。我可以在同一个查询中执行此操作吗?
一个属性有几个单元。他们都隶属于一个“团队”(想想用户名)。
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