如何过滤我的 SELECT 中的 GROUP_CONCAT

How to filter the GROUP_CONCAT in my SELECT

我正在尝试 SELECT(所有多个)来自 Wordpress 的评论,这些评论与 post(wp_comments.comment_content)和 GROUP_CONCAT 有关,但我只想select 那些不包含文本字符串 "status" 的评论。如果根本没有评论,或者只有包含 "status" 的评论,我仍然希望在结果中看到这些记录,只是不想得到 comments 的任何回复。

当我尝试将类似于 [WHERE wp_comments.comment_content NOT LIKE "%status%"] 的条件放在完整查询的末尾时,只有评论包含 "status" 的记录不会根本不显示,我仍然需要获取那些记录,只是没有评论。

我想尝试类似下面的版本,但这会引发错误并且根本不会吐出任何数据。 (除了评论 selection 部分之外,整个查询按预期工作 btw..)。

也许我在错误的地方加入了 wp_comments table,使用了错误的加入,没有使用格式正确的嵌套 SELECT 或类似的,也许它需要一个单独的 SELECT 最后,这样我就可以以一种不影响哪些记录总体上 select 的方式取回我想要的评论。不确定..

知道我做错了什么或如何解决这个问题吗?

这是我的问题,在此先感谢您的指点!

select wp_woocommerce_order_itemmeta.meta_value as firstwoometavalue, 
wp_postmeta.meta_value as firstwpmetavalue, Y.meta_value as ymetavalue, 
Z.meta_value as zmetavalue, X.meta_value as xmetavalue, 
(GROUP_CONCAT(wp_comments.comment_content) as commentcontent 
WHERE wp_comments.comment_type = "order_note" AND 
wp_comments.comment_content NOT LIKE "%status%")
FROM wp_postmeta 
left JOIN wp_postmeta as Y
ON wp_postmeta.post_id = Y.post_id
left JOIN wp_posts
ON wp_postmeta.post_id = wp_posts.ID
left JOIN wp_woocommerce_order_items
ON wp_woocommerce_order_items.order_id = wp_posts.ID
left JOIN wp_woocommerce_order_itemmeta
ON wp_woocommerce_order_itemmeta.order_item_id = wp_woocommerce_order_items.order_item_id
left JOIN wp_woocommerce_order_itemmeta as Z
ON wp_woocommerce_order_itemmeta.order_item_id = Z.order_item_id
left JOIN wp_woocommerce_order_itemmeta as X
ON wp_woocommerce_order_itemmeta.order_item_id = X.order_item_id
left JOIN wp_comments
ON wp_comments.comment_post_ID = wp_posts.ID
where 1=1
AND wp_woocommerce_order_itemmeta.meta_key ="Adults"
AND wp_postmeta.meta_key ="_billing_first_name"
AND Y.meta_key ="_billing_last_name"
AND Z.meta_key ="Booking Type"
AND Z.meta_value LIKE "%'.$showlocation.'%"
AND X.meta_key ="Booking Date"
AND X.meta_value = "'.$showdate.'"
AND wp_posts.post_status ="wc-completed" 
GROUP BY wp_posts.ID

这个有效

 SELECT 
wp_woocommerce_order_itemmeta.meta_value AS Adults,
wp_postmeta.meta_value AS FirstName,
jn_postmeta_lastname.meta_value AS LastName,
jn_woocommerce_order_itemmeta_location.meta_value AS Location,
jn_woocommerce_order_itemmeta_date.meta_value AS ShowDate,
(SELECT 
        GROUP_CONCAT(wp_comments.comment_content)
    FROM
        wp_comments
    WHERE
        wp_comments.comment_content NOT LIKE '%status%'
            AND wp_comments.comment_post_ID = wp_posts.ID) Notes
 FROM
wp_postmeta
    LEFT JOIN
wp_postmeta AS jn_postmeta_lastname ON wp_postmeta.post_id = jn_postmeta_lastname.post_id
    LEFT JOIN
wp_posts ON wp_postmeta.post_id = wp_posts.ID
    LEFT JOIN
wp_woocommerce_order_items ON wp_woocommerce_order_items.order_id = wp_posts.ID
    LEFT JOIN
wp_woocommerce_order_itemmeta ON wp_woocommerce_order_itemmeta.order_item_id = wp_woocommerce_order_items.order_item_id
    LEFT JOIN
wp_woocommerce_order_itemmeta AS jn_woocommerce_order_itemmeta_location ON wp_woocommerce_order_itemmeta.order_item_id = jn_woocommerce_order_itemmeta_location.order_item_id
    LEFT JOIN
wp_woocommerce_order_itemmeta AS jn_woocommerce_order_itemmeta_date ON wp_woocommerce_order_itemmeta.order_item_id = jn_woocommerce_order_itemmeta_date.order_item_id
    LEFT JOIN
wp_comments ON wp_comments.comment_post_ID = wp_posts.ID
WHERE
1 = 1
    AND (wp_postmeta.meta_key = '_billing_first_name'
    AND jn_postmeta_lastname.meta_key = '_billing_last_name'
    AND wp_woocommerce_order_itemmeta.meta_key = 'Adults'
    AND jn_woocommerce_order_itemmeta_location.meta_key = 'Booking Type'
    AND jn_woocommerce_order_itemmeta_location.meta_value LIKE "%'.$showlocation.'%"
    AND jn_woocommerce_order_itemmeta_date.meta_key = 'Booking Date'
    AND jn_woocommerce_order_itemmeta_date.meta_value = "'.$showdate.'"
    AND wp_posts.post_status = 'wc-completed'
GROUP BY wp_posts.ID