廢話不多說,直接上代碼文章來源地址http://www.zghlxwxcb.cn/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
文章來源:http://www.zghlxwxcb.cn/news/detail-422448.html
到了這里,關(guān)于MySQL中使用IF子查詢實現(xiàn)條件判斷(where之后用if)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!