gpt4 book ai didi

sql - 有没有一种方法可以让我在 where 条件下拥有像 if-else 这样的功能

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

我有以下表格结构。根据收到的请求类型,我应该能够选择正确的列来匹配值。

| resource_id | result | request          | 
| | 15127 | /campaign/add |
| 15127 | | /campaign/modify |

例如:

如果请求类似于 /campaign/add,则应将结果与用户发送的数字进行比较,否则应选择 resource_id。

程序上我可以说

if(request.equals())
fetch values from database where resource_id = 15127
else
fetch values from database where resource_id = 15127

现在我需要使用数据库做同样的事情。

最佳答案

您可以使用 CASE 表达式来做到这一点:

select *
from the_table
where case
when request = '/campaign/add' then result
when request = '/campaign/modify' then resource_id
end = number_sent_by_the_user

关于sql - 有没有一种方法可以让我在 where 条件下拥有像 if-else 这样的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42368115/

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