废话不多说,直接上代码文章来源地址https://www.toymoban.com/news/detail-422448.html
SELECT
z.*
FROM
(
SELECT
t.*
FROM
(
SELECT
a.unit_id,
a.total_score,
a.score_level,
a.optimize_total_score,
a.optimize_score_level,
a.create_time,
b.score_revise_state
FROM
risk_assess_record a
LEFT JOIN risk_template b ON a.temp_id = b.id
WHERE
unit_id = '340100DW1600681791889342464'
AND total_score IS NOT NULL
ORDER BY
create_time DESC
LIMIT 2000
) t
GROUP BY
t.unit_id
) z
WHERE
IF
( z.score_revise_state = 1, z.optimize_score_level = '3', z.score_level = '3' )
ORDER BY
total_score DESC
文章来源:https://www.toymoban.com/news/detail-422448.html
到了这里,关于MySQL中使用IF子查询实现条件判断(where之后用if)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!