SELECT IF(price == null, 0, price) FROM trips
WHERE id=9 and prices LIKE "%|s|1|%" and prices LIKE "%|ss|24|%"
如果LIKE "%|ss|2|%
"执行该价格,如果有LIKE "%|ss|24|%"
不执行任何操作表明您有使其0
。
最佳答案
没有显示任何内容,因为没有包含“|s|1|”的价格值和“|ss|24|”。我认为你应该使用 OR 来代替。
SELECT IF(price == null, 0, price) FROM trips
WHERE id=9 and (prices LIKE "%|s|1|%" OR prices LIKE "%|ss|24|%");
关于MySQL IF ELSE 真假,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50367595/