我有一个工作生成的SQL查询,但是我无法理解我如何计算它!
GROUP BY
函数阻止正常COUNT(*)
工作..希望有人可以提供帮助。
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
由于
答案 0 :(得分:4)
删除GROUP BY
并将SELECT
更改为仅COUNT(DISTINCT wposts.post_content)
,以获取此查询返回的行数。
答案 1 :(得分: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