需要有关此查询的帮助...
SELECT field_value, file
FROM " . $wpdb->prefix . "cf7dbplugin_submits
WHERE form_name = '" . $form_name . "' AND submit_time = '" . $submit_time . "' AND (field_name = 'csv_parts_file' OR field_name = 'csv_paste_file');
基本上,我想在这里只返回1行,但我需要获取field_name = 'csv_parts_file'
(如果存在)的行,但如果不存在,那么我需要将行放到{{1相反。我想我可能需要在这里做field_name = 'csv_paste_file'
,但不知道如何做。对CASE陈述没有多少经验。
这里非常感谢任何帮助。
答案 0 :(得分:0)
实现这一目标有点奇怪,但它应该有效:
SELECT field_value, file, IF(field_name = 'csv_parts_file', 0, 1) as condition
FROM " . $wpdb->prefix . "cf7dbplugin_submits
WHERE form_name = '" . $form_name . "'
AND submit_time = '" . $submit_time . "'
AND (field_name = 'csv_parts_file' OR field_name = 'csv_paste_file')
ORDER BY condition
LIMIT 1