我想通过执行例如:以下查询来检索数据库中的数据:
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或2,1,3或1,2
而不是上述查询中的&#39; ,我希望传递select语句(从订单中选择OrderID,其中OrderName =&#39; ABCD&#39; < /强>)。
我已经尝试但没有明白语法。 请任何人都可以建议我如何正确执行此操作。 感谢。
答案 0 :(得分: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 ..;