gpt4 book ai didi

mysql - 如果/那么语句

转载 作者:行者123 更新时间:2023-11-29 11:43:13 24 4
gpt4 key购买 nike

$data = $con->query("SELECT id, content FROM table1 WHERE id IN (". $column['data'] .")");

我已经得到了上面的代码,我需要向其中添加 if then 语句。

if table1.draftid = 0, then select content from table 1
if table1.draftid != 0, then select content from table 2

Just for reference.... IF TABLE1.DRAFTID != 0, then table1.draftid = table2.id

我尝试了以下方法..

$data = $con->query("SELECT table1.id,

(case
when table1.draftid = 0 then table1.content
when table1.draftid != 0 then (select table2.content from table2 where table1.draftid = table2.id)
end) as data,


FROM table1
JOIN table2 ON table1.draftid = table2.id
WHERE table1.id IN (". $column['data'] .")");

使用示例

> Table 1
>
>id = 1
>
>draftid = 1
>
>content = Table 1 Test

---------

> Table 2
>
> id = 1
>
> content = Table 2 Content
<小时/>

The desired results: If table 1 draftid = 0, then it would call the content from table 1. BUT, if table1.draftid != 0 (In example: 1), >then it would pull the content from table 2 where table1.draftid = table2.id

最佳答案

你能试试这个吗?

$data = $con->query("SELECT table1.id,

(case
when table1.draftid = 0 then table1.content
when table1.draftid != 0 then table2.content
end) as data,


FROM table1
JOIN table2 ON table1.draftid = table2.id
WHERE table1.id IN (". $column['data'] .")");

关于mysql - 如果/那么语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35409195/

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