2011-08-09 119 views
0

我有一個工作生成的SQL查詢,但我無法計算出我如何計算它! GROUP BY函數停止正常工作COUNT(*) ..希望有人可以提供幫助。幫助一個SQL查詢

SELECT wposts.* FROM wp_posts wposts, wp_postmeta wpostmeta 
WHERE wposts.ID = wpostmeta.post_id 
AND wpostmeta.meta_key = 'phone' 
AND wpostmeta.meta_value = '1542' 
AND wposts.post_status = 'publish' 
AND wposts.post_type = 'tips' || wposts.ID = wpostmeta.post_id 
AND wpostmeta.meta_key = 'phone' 
AND wpostmeta.meta_value = '1541' 
AND wposts.post_status = 'publish' 
AND wposts.post_type = 'tips' || ........ 
GROUP BY wposts.post_content 
ORDER BY wposts.post_title ASC 

感謝

回答

4

取出GROUP BY,改變SELECTCOUNT(DISTINCT wposts.post_content)得到這個查詢將返回的行數。

+0

謝謝!我花了很多年試圖解決這個問題......應該問早些時候:) –

1
SELECT COUNT(DISTINCT wposts.post_content) 
WHERE wposts.ID = wpostmeta.post_id 
AND wpostmeta.meta_key = 'phone' 
AND wpostmeta.meta_value = '1542' 
AND wposts.post_status = 'publish' 
AND wposts.post_type = 'tips' || wposts.ID = wpostmeta.post_id 
AND wpostmeta.meta_key = 'phone' 
AND wpostmeta.meta_value = '1541' 
AND wposts.post_status = 'publish' 
AND wposts.post_type = 'tips' || ........ 
ORDER BY wposts.post_title ASC