gpt4 book ai didi

mysql - sql查询如何使用IF和ELSE语句

转载 作者:行者123 更新时间:2023-11-30 23:05:34 25 4
gpt4 key购买 nike

我有查询要选择以获得答案值。我需要检查它是回答还是空。我使用 (d.AM_Answer OR null) 它不起作用。它只取空值。所以,我已经像下面这样更改了我的查询,但它不起作用。

SELECT a.QM_ID,
a.QM_QCM_ID,
a.QM_Question,
a.QM_Type,
a.QM_Parent_Id,
c.AM_Answer,
c.AM_Comments
FROM question_master a
INNER JOIN Assessment_master c ON (c.AM_QM_ID = a.QM_ID
AND c.AM_HNM_ID = %d
AND c.AM_HM_ID = %d
AND c.AM_ASM_Local_Id = %@)
WHERE a.QM_Parent_Id = 0
AND a.QM_Status = 'A'
AND a.QM_QCM_ID = %@
AND a.QM_QRM_Id = %@ IF(d.AM_Answer IS NULL) THEN
UNION
SELECT b.QM_ID,
b.QM_QCM_ID,
b.QM_Question,
b.QM_Type,
b.QM_Parent_Id,
NULL,
NULL
FROM question_master b
INNER JOIN Assessment_master d ON ((d.AM_QM_ID = b.QM_Parent_Id
OR d.AM_QM_ID = b.QM_ID)
AND d.AM_HNM_ID = %d
AND d.AM_HM_ID = %d
AND d.AM_ASM_Local_Id = %@)
WHERE b.QM_Parent_Id != 0
AND b.QM_Status = 'A'
AND b.QM_QCM_ID = %@
AND b.QM_QRM_Id = %@ ELSE IF(d.AM_Answer IS NOT NULL) THEN
UNION
SELECT b.QM_ID,
b.QM_QCM_ID,
b.QM_Question,
b.QM_Type,
b.QM_Parent_Id,
d.AM_Answer,
d.AM_Comments
FROM question_master b
INNER JOIN Assessment_master d ON ((d.AM_QM_ID = b.QM_Parent_Id
OR d.AM_QM_ID = b.QM_ID)
AND d.AM_HNM_ID = %d
AND d.AM_HM_ID = %d
AND d.AM_ASM_Local_Id = %@)
WHERE b.QM_Parent_Id != 0
AND b.QM_Status = 'A'
AND b.QM_QCM_ID = %@
AND b.QM_QRM_Id = %@ END IF

最佳答案

您可以将条件 d.answer 不为空来选择非空答案。

关于mysql - sql查询如何使用IF和ELSE语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22059924/

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