gpt4 book ai didi

mysql - SQLworkbench中有关LIKE子句和Select语句的查询

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

我想通过执行以下查询从数据库检索数据:

  Select * from Employee emp
inner join Department dept on emp.empid=dept.empid
where dept.OrderID like '%1' OR
dept.OrderID like '%,1' OR
dept.OrderID like '%,1,%' OR
dept.OrderID like '1,%'
order by ..;

** 上述条件是--> 1 OR 2,1 OR 2,1,3 OR 1,2

我想传递 select 语句(从 OrderName= 'ABCD' 的订单中选择 OrderID,其中 OrderName= 'ABCD'),而不是上面的查询中的 '1'

我已经尝试过,但没有掌握语法。请任何人都可以建议我如何正确执行此操作。谢谢。

最佳答案

试试这个:

     Select * from Employee emp
inner join Department dept on emp.empid=dept.empid
where dept.OrderID like CONCAT('%', (select OrderID from Orders where OrderName= 'ABCD')) OR
dept.OrderID like CONCAT('%,', (select OrderID from Orders where OrderName= 'ABCD')) OR
dept.OrderID like CONCAT('%,', (select OrderID from Orders where OrderName= 'ABCD'), ',%') OR
dept.OrderID like CONCAT((select OrderID from Orders where OrderName= 'ABCD'), ',%')
order by ..;

关于mysql - SQLworkbench中有关LIKE子句和Select语句的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24680951/

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