答案 0 :(得分:0)
SELECT c.name , c.custom_message , d.log_id , c.price , c.quantity ,
GROUP_CONCAT(case when d.form_id=2 then d.value end) AS first_name ,
GROUP_CONCAT(case when d.form_id=3 then d.value end) AS last_name
FROM wp_wpsc_cart_contents c
JOIN wp_wpsc_submited_form_data d ON d.log_id = c.purchaseid
WHERE c.name LIKE '%%'
GROUP BY d.log_id
ORDER BY c.name
答案 1 :(得分:0)
您可以使用case
表达式来过滤特定的表单字段。就SQL语法而言,您可以为每个form_id
获得多个结果,因此您必须对它们进行聚合:
, GROUP_CONCAT(case when d.form_id=2 then d.value end) AS first_name
, GROUP_CONCAT(case when d.form_id=3 then d.value end) AS last_name
答案 2 :(得分:0)
迟到的答案,但如果你尝试下面的话怎么办
SELECT c.name
, c.custom_message
, d.log_id
, c.price
, c.quantity
,(select GROUP_CONCAT(value)
from wp_wpsc_submited_form_data
where value like '%name%' and log_id = d.log_id)
AS VALUE
FROM wp_wpsc_cart_contents c
JOIN wp_wpsc_submited_form_data d
ON d.log_id = c.purchaseid
WHERE c.name LIKE '%%'
GROUP BY d.log_id
ORDER BY c.name
你可以使用你提供的同一个小提琴; http://sqlfiddle.com/#!2/a4bff/92