加入查询需要更多时间

时间:2012-06-28 14:42:49

标签: mysql join

My Query花费更多时间来提供输出,我可以创建可以轻松输出的查询。

SELECT DISTINCT(property.Project_Name), property.Property_Type, ROUND(AVG(property.Unit_Price_psf)), property.Transacted_Price
FROM property
JOIN avg_property
WHERE avg_property.Project_Name=property.Project_Name
AND avg_property.Median_Price BETWEEN '$mdpr1' AND '$mdpr2'
GROUP BY property.Project_Name

1 个答案:

答案 0 :(得分:0)

重写distinct

的替代方案
SELECT
  property.Project_Name,
  property.Property_Type,
  ROUND(AVG(property.Unit_Price_psf)),
  property.Transacted_Price
FROM property
  JOIN avg_property
WHERE exists(select
           Project_Name
         from property
         group by Project_Name)
    and avg_property.Project_Name = property.Project_Name
    AND avg_property.Median_Price BETWEEN '$mdpr1'
    AND '$mdpr2'
GROUP BY property.Project_Name