gpt4 book ai didi

sql - mysql查询if else语句?

转载 作者:行者123 更新时间:2023-11-29 01:12:33 28 4
gpt4 key购买 nike

我有这个 sql 查询:

SELECT
S.SEARCH,
S.STATUS,
C.TITLE AS CategoryName,
E.SEARCH_ENGINES AS Engine,
S.RESULTS,
S.DATE,
S.TOTAL_RESULTS AS Total,
S.ID

FROM
PLD_SEARCHES AS S
Join PLD_CATEGORY AS C ON C.ID = S.CATEGORY_ID
Join PLD_SEARCH_ENGINES AS E ON S.SEARCH_ENGINES_ID = E.ID
ORDER BY S.DATE ASC

我想确定 S.STATUS 是 1 还是 0,并根据这些值在查询中返回 COMPLETEPENDING结果

最佳答案

SELECT S.SEARCH, if(S.STATUS=1,'COMPLETE','PENDING') as STATUS, 
C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine, S.RESULTS,
S.DATE, S.TOTAL_RESULTS AS Total, S.ID
FROM PLD_SEARCHES AS S
Join PLD_CATEGORY AS C ON C.ID = S.CATEGORY_ID
Join PLD_SEARCH_ENGINES AS E ON S.SEARCH_ENGINES_ID = E.ID
ORDER BY S.DATE ASC

IF functionif(x=y, TRUE RESULT, FALSE RESULT)

if(S.STATUS=1,'COMPLETE','PENDING')

关于sql - mysql查询if else语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2443583/

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