我有一个类似这样的查询,我想返回in案例中的所有值以及匹配的行数。
从用户中选择id,name,age from USERS WHERE id IN (1,75,75);
返回
1|约翰|25
75|山姆|30
但是我想要的是
1|约翰|25
75|山姆|30
75|山姆|30
这样的事情在sql中是可能的吗?如果你们对此有解决方案,我将不胜感激。
谢谢
发布于 2020-06-18 08:18:26
您可以改用join:
select u.*
from (select 1 as id union all select 75 union all select 75) i join
users u
on u.id = i.id;更简洁的格式使用values()
with i(id) as (
values (1), (75), (75)
)
select u.*
from i join
users u
on u.id = i.id;https://stackoverflow.com/questions/62440359
复制相似问题