当我在查询中使用“GROUP_CONCAT”和“HAVING”时,如何计算MySQL结果?

时间:2016-03-17 05:12:01

标签: mysql count group-concat having

所以我有一个我想要的MySQL查询。最初我使用wordpress' get_results("")但我还需要在不同的查询中计算总数,因为在我的原始查询中我限制结果来创建页面。

所以这是我的原始查询,有谁知道我怎么算这个?

SELECT wpp.ID, post_title, wp_terms.name AS category, wp_terms.slug AS slug, supplier_company, 
    GROUP_CONCAT(wp_terms.slug SEPARATOR ', ') AS allslug,
    GROUP_CONCAT(wp_terms.name SEPARATOR ', ') AS allcatname
    FROM wp_posts AS wpp
    LEFT JOIN wp_term_relationships ON wpp.ID = object_id
    LEFT JOIN wp_terms ON term_taxonomy_id = wp_terms.term_id
    LEFT JOIN wp_teleapo_supplier AS s ON wpp.post_author = s.ID



    /* BASIC SEARCH on normal fields */
    WHERE post_type = 'post' 


    GROUP BY wpp.ID

    /* SEARCH on CONCAT FIELDS*/
    HAVING

    (post_title LIKE '%%'
    OR allcatname LIKE '%%'
    OR allslug LIKE '%%'
    OR supplier_company LIKE '%%')
    AND (allslug LIKE '%health-and-beauty%'
    ) AND (allslug LIKE '%%'
    ) AND 

    /* ADD EXTRA SEARCH TAGS: */
    /* Language tag */
     allslug LIKE '%english%' 
    /* ..... tag */

    /* AND allslug LIKE '%......... %' */
    ORDER BY post_date DESC 

1 个答案:

答案 0 :(得分:1)

只需在SELECT查询后直接检索found_rows

select found_rows();