select s.user, t.code
from (
select 'user1' as user union all
select 'user2' union all
select 'user3' union all
select 'user4'
) as s
left join mytable t on s.user = t.user;
select user,code
from (
select 'user1' as user, 'abc' as code union all
select 'user2','def' union all
select 'user3', 'ghi' union all
select 'user4' ,NULL
) as s
where code is null;
2条答案
按热度按时间iq3niunx1#
你可以通过将你的条件作为子查询传递,然后将
left join
应用到你的表中:字符串
结果如下:
| 用户|代码|
| --|--|
| user1|代码1|
| user2| null|
| user3|代码2|
| 用户4|代码4|
Demo here
66bbxpm52#
可以直接在where子句中过滤
字符串