【发布时间】:2021-07-29 10:07:16
【问题描述】:
用户表:
| id | first_name | last_name |
|---|---|---|
| 1 | C1 | ABC |
| 2 | C2 | XYZ |
| 3 | C3 | PQR |
查询:
select first_name,last_name
from user
where "first_name" like '%AB%' or where "last_name" like '%AB%'
结果
| id | first_name | last_name |
|---|---|---|
| 1 | C1 | ABC |
我需要查询只返回用户表中匹配的列,这里姓氏与 AB 匹配,所以它应该返回 last_name 值,first_name 应该返回为 null。
如何做到这一点?
预期的结果应该是
| id | first_name | last_name |
|---|---|---|
| 1 | null | ABC |
【问题讨论】:
标签: sql postgresql