gpt4 book ai didi

php - 如何在mysql查询的if条件语句中调用子查询

转载 作者:行者123 更新时间:2023-11-29 06:46:05 26 4
gpt4 key购买 nike

我有两个表 table1 和 table2。当 status=1 时我需要 table1 的值

    SELECT type, no, 
CASE WHEN status = '0' THEN 'Vacant'
WHEN status = '2' THEN 'Repair'
ELSE (SELECT `field1` FROM `table1` WHERE `field2`=10) AS test END AS addr
FROM table2

此查询输出错误 #1064

如何在单个 MYSQL 查询中获取值?

最佳答案

SELECT type, no, 
CASE WHEN status = '0' THEN 'Vacant'
WHEN status = '2' THEN 'Repair'
WHEN status = '1' (SELECT `field1` FROM `table1` WHERE `field2`=10) END AS addr FROM table2

如果你尝试这段代码那么你不会得到错误

关于php - 如何在mysql查询的if条件语句中调用子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18634328/

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