當前,我正在運行此SQL查詢以檢索商店定位器的自定義帖子。一切都很好,除非我希望它返回項目,即使「電話」字段爲空。截至目前只會拉那些該領域填補了那些即使字段爲空,您如何運行SQL查詢返回
這是運行時我的查詢的樣子:
任何有線索? (也就是有一個更有效的方式來運行這個?)
SELECT wp_posts.post_title as name,
address.meta_value as address,
latitude.meta_value as lat,
longitude.meta_value as lng,
telephone.meta_value as phone,
(3959 * acos(
cos(radians('%s')) *
cos(radians(CONVERT(latitude.meta_value, DECIMAL(10, 6)))) *
cos(radians(CONVERT(longitude.meta_value, DECIMAL(10, 6))) - radians('%s')) +
sin(radians('%s')) * sin(radians(CONVERT(latitude.meta_value, DECIMAL(10, 6))))
)) AS distance
FROM wp_postmeta as address, wp_postmeta as latitude, wp_postmeta as longitude, wp_postmeta as telephone,
wp_posts
WHERE
(wp_posts.ID = address.post_id
AND address.meta_key = '_dealer_address')
AND (wp_posts.ID = latitude.post_id
AND latitude.meta_key = '_dealer_latitude')
AND (wp_posts.ID = longitude.post_id
AND longitude.meta_key = '_dealer_longitude')
AND (wp_posts.ID = telephone.post_id
AND telephone.meta_key = '_dealer_telephone')
或重寫使用電話的東西,而不是一個內部聯接左連接。 – 2011-05-12 19:15:37
Marc B--我已經成功地使用了你的方法,如果你把這個作爲n答案重新發布,我會設置爲接受的答案。謝謝! – Joe 2011-05-12 21:17:37