我正在使用以下查询:
SELECT `submit_time` AS 'Submitted',
max(if(`field_name`='your-name', `field_value`, null )) AS 'your-name',
max(if(`field_name`='your-email', `field_value`, null )) AS 'your-email',
max(if(`field_name`='your-phone', `field_value`, null )) AS 'your-phone',
max(if(`field_name`='Submitted From', `field_value`, null )) AS 'Submitted From',
GROUP_CONCAT(if(`file` is null or length(`file`) = 0, null, `field_name`)) AS 'fields_with_file'
FROM `wp_cf7dbplugin_submits`
WHERE `form_name` = 'test form'
GROUP BY `submit_time`
ORDER BY `submit_time` DESC
LIMIT 0,100
这让我返回了前 100 行(所有字段值都存在)。
我想要的是获得一个特定的行。为此,我在 WHERE 子句部分的上面的查询中附加了这一行( AND field_name='your-email' AND field_value = 'test@gm.com')
。现在最终的查询是:
SELECT `submit_time` AS 'Submitted',
max(if(`field_name`='your-name', `field_value`, null )) AS 'your-name',
max(if(`field_name`='your-email', `field_value`, null )) AS 'your-email',
max(if(`field_name`='your-phone', `field_value`, null )) AS 'your-phone',
max(if(`field_name`='Submitted From', `field_value`, null )) AS 'Submitted From',
GROUP_CONCAT(if(`file` is null or length(`file`) = 0, null, `field_name`)) AS 'fields_with_file'
FROM `wp_cf7dbplugin_submits`
WHERE `form_name` = 'test form' AND field_name=your-email AND field_value = 'test@gm.com'
GROUP BY `submit_time`
ORDER BY `submit_time` DESC
但它只返回您的电子邮件值,其他字段值变为 NULL(就像您的姓名字段为 NULL)。
有谁知道如何做到这一点/我可以在哪里找到解决方案?