MySql 查询 - 多个 SELECT 语句
MySql Query - Multiple SELECT statements
我正在创建这个 MYSQL 查询:
SELECT
GROUP_CONCAT(if(field_number = '2', value, NULL)) AS 'Field1',
GROUP_CONCAT(if(field_number = '3', value, NULL)) AS 'Field2',
GROUP_CONCAT(if(field_number = '4', value, NULL)) AS 'Field3',
GROUP_CONCAT(if(field_number = '5', value, NULL)) AS 'Field4',
GROUP_CONCAT(if(field_number = '6', value, NULL)) AS 'Field5',
GROUP_CONCAT(if(field_number = '7', value, NULL)) AS 'Field6',
GROUP_CONCAT(if(field_number = '8', value, NULL)) AS 'Field7',
GROUP_CONCAT(if(field_number = '9', value, NULL)) AS 'Field8'
from wp_rg_lead_detail WHERE form_id = "3"
GROUP BY lead_id;
上面的查询我得到了很好的结果。我有另一个 table 存储每个条目的日期,并且可以通过 form_id
.
进行交叉检查
我用来获取日期的查询如下:
SELECT date_created FROM wp_rg_lead WHERE form_id="3";
我需要加入两个查询,以便将所有结果集中在一起。
由于您没有提供表格结构,我的猜测是:
SELECT
wp2.date_created,
GROUP_CONCAT(if(field_number = '2', value, NULL)) AS 'Field1',
GROUP_CONCAT(if(field_number = '3', value, NULL)) AS 'Field2',
GROUP_CONCAT(if(field_number = '4', value, NULL)) AS 'Field3',
GROUP_CONCAT(if(field_number = '5', value, NULL)) AS 'Field4',
GROUP_CONCAT(if(field_number = '6', value, NULL)) AS 'Field5',
GROUP_CONCAT(if(field_number = '7', value, NULL)) AS 'Field6',
GROUP_CONCAT(if(field_number = '8', value, NULL)) AS 'Field7',
GROUP_CONCAT(if(field_number = '9', value, NULL)) AS 'Field8'
FROM wp_rg_lead_detail wp1
LEFT JOIN wp_rg_lead wp2
ON wp1.lead_id = wp2.id
WHERE wp1.form_id = "3"
GROUP BY wp1.lead_id;
我正在创建这个 MYSQL 查询:
SELECT
GROUP_CONCAT(if(field_number = '2', value, NULL)) AS 'Field1',
GROUP_CONCAT(if(field_number = '3', value, NULL)) AS 'Field2',
GROUP_CONCAT(if(field_number = '4', value, NULL)) AS 'Field3',
GROUP_CONCAT(if(field_number = '5', value, NULL)) AS 'Field4',
GROUP_CONCAT(if(field_number = '6', value, NULL)) AS 'Field5',
GROUP_CONCAT(if(field_number = '7', value, NULL)) AS 'Field6',
GROUP_CONCAT(if(field_number = '8', value, NULL)) AS 'Field7',
GROUP_CONCAT(if(field_number = '9', value, NULL)) AS 'Field8'
from wp_rg_lead_detail WHERE form_id = "3"
GROUP BY lead_id;
上面的查询我得到了很好的结果。我有另一个 table 存储每个条目的日期,并且可以通过 form_id
.
我用来获取日期的查询如下:
SELECT date_created FROM wp_rg_lead WHERE form_id="3";
我需要加入两个查询,以便将所有结果集中在一起。
由于您没有提供表格结构,我的猜测是:
SELECT
wp2.date_created,
GROUP_CONCAT(if(field_number = '2', value, NULL)) AS 'Field1',
GROUP_CONCAT(if(field_number = '3', value, NULL)) AS 'Field2',
GROUP_CONCAT(if(field_number = '4', value, NULL)) AS 'Field3',
GROUP_CONCAT(if(field_number = '5', value, NULL)) AS 'Field4',
GROUP_CONCAT(if(field_number = '6', value, NULL)) AS 'Field5',
GROUP_CONCAT(if(field_number = '7', value, NULL)) AS 'Field6',
GROUP_CONCAT(if(field_number = '8', value, NULL)) AS 'Field7',
GROUP_CONCAT(if(field_number = '9', value, NULL)) AS 'Field8'
FROM wp_rg_lead_detail wp1
LEFT JOIN wp_rg_lead wp2
ON wp1.lead_id = wp2.id
WHERE wp1.form_id = "3"
GROUP BY wp1.lead_id;