gpt4 book ai didi

mysql - SQL 查询将每个值返回为 NULL

转载 作者:行者123 更新时间:2023-11-30 22:27:10 25 4
gpt4 key购买 nike

我有一个 SQL 查询,它只是在每个字段中返回一个 NULL 值。它针对数据库中输入的数据量返回正确的行数,但每个列值都显示为 NULL,而不是 MySQL 中字段的值。

谁能给我一些建议吗?

SELECT items.form_id as 'Form ID',
MAX(IF('field_id' LIKE 88,meta_value,NULL)) AS 'User ID',
MAX(IF('field_id' LIKE 96,meta_value,NULL)) AS 'Display Name',
MAX(IF('field_id' LIKE 95,meta_value,NULL)) AS 'User Role',
MAX(IF('field_id' LIKE 301,meta_value,NULL)) AS 'Your District',
MAX(IF('field_id' LIKE 97,meta_value,NULL)) AS 'Time Duty Logged',
MAX(IF('field_id' LIKE 84,meta_value,NULL)) AS 'Date of Duty',
MAX(IF('field_id' LIKE 85,meta_value,NULL)) AS 'Duty Start Time',
MAX(IF('field_id' LIKE 86,meta_value,NULL)) AS 'Duty End Time',
MAX(IF('field_id' LIKE 139,meta_value,NULL)) AS 'Duty Status',
MAX(IF('field_id' LIKE 142,meta_value,NULL)) AS 'Duty Type',
MAX(IF('field_id' LIKE 174,meta_value,NULL)) AS 'Which Event?',
MAX(IF('field_id' LIKE 103,meta_value,NULL)) AS 'Total Hours',
MAX(IF('field_id' LIKE 135,meta_value,NULL)) AS 'Duty Details',
MAX(IF('field_id' LIKE 136,meta_value,NULL)) AS 'End Section',
MAX(IF('field_id' LIKE 227,meta_value,NULL)) AS 'User Details',
MAX(IF('field_id' LIKE 228,meta_value,NULL)) AS 'End Section'
FROM wp_frm_item_metas as meta
JOIN wp_frm_items as items ON (items.id = meta.item_id)
WHERE items.form_id LIKE 6
GROUP BY meta.item_id

我现在也尝试了以下方法,但我仍然用 NULL 代替每个字段值

SELECT items.form_id as 'Form ID',
MAX(IF('field_id' = 88,meta_value,NULL)) AS 'User_ID',
MAX(IF('field_id' = 96,meta_value,NULL)) AS 'Display_Name',
MAX(IF('field_id' = 95,meta_value,NULL)) AS 'User_Role',
MAX(IF('field_id' = 301,meta_value,NULL)) AS 'Your_District',
MAX(IF('field_id' = 97,meta_value,NULL)) AS 'Time_Duty_Logged',
MAX(IF('field_id' = 84,meta_value,NULL)) AS 'Date_of_Duty',
MAX(IF('field_id' = 85,meta_value,NULL)) AS 'Duty_Start_Time',
MAX(IF('field_id' = 86,meta_value,NULL)) AS 'Duty_End_Time',
MAX(IF('field_id' = 139,meta_value,NULL)) AS 'Duty_Status',
MAX(IF('field_id' = 142,meta_value,NULL)) AS 'Duty_Type',
MAX(IF('field_id' = 174,meta_value,NULL)) AS 'Which_Event?',
MAX(IF('field_id' = 103,meta_value,NULL)) AS 'Total_Hours',
MAX(IF('field_id' = 135,meta_value,NULL)) AS 'Duty_Details',
MAX(IF('field_id' = 136,meta_value,NULL)) AS 'End_Section',
MAX(IF('field_id' = 227,meta_value,NULL)) AS 'User_Details',
MAX(IF('field_id' = 228,meta_value,NULL)) AS 'End_Section'
FROM wp_frm_item_metas as meta
JOIN wp_frm_items as items ON (items.id = meta.item_id)
WHERE items.form_id = 6
GROUP BY meta.item_id

最佳答案

两件事:您不必引用 field_id 列名称,并且您可能不想对数值使用 LIKE

SELECT items.form_id as 'Form ID',
MAX(IF(field_id = 88,meta_value,NULL)) AS 'User_ID',
MAX(IF(field_id = 96,meta_value,NULL)) AS 'Display_Name',
MAX(IF(field_id = 95,meta_value,NULL)) AS 'User_Role',
MAX(IF(field_id = 301,meta_value,NULL)) AS 'Your_District',
MAX(IF(field_id = 97,meta_value,NULL)) AS 'Time_Duty_Logged',
MAX(IF(field_id = 84,meta_value,NULL)) AS 'Date_of_Duty',
MAX(IF(field_id = 85,meta_value,NULL)) AS 'Duty_Start_Time',
MAX(IF(field_id = 86,meta_value,NULL)) AS 'Duty_End_Time',
MAX(IF(field_id = 139,meta_value,NULL)) AS 'Duty_Status',
MAX(IF(field_id = 142,meta_value,NULL)) AS 'Duty_Type',
MAX(IF(field_id = 174,meta_value,NULL)) AS 'Which_Event?',
MAX(IF(field_id = 103,meta_value,NULL)) AS 'Total_Hours',
MAX(IF(field_id = 135,meta_value,NULL)) AS 'Duty_Details',
MAX(IF(field_id = 136,meta_value,NULL)) AS 'End_Section',
MAX(IF(field_id = 227,meta_value,NULL)) AS 'User_Details',
MAX(IF(field_id = 228,meta_value,NULL)) AS 'End_Section'
FROM wp_frm_item_metas as meta
JOIN wp_frm_items as items ON (items.id = meta.item_id)
WHERE items.form_id = 6
GROUP BY meta.item_id

关于mysql - SQL 查询将每个值返回为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34861457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com