Postgresql 模式匹配

Postgresql pattern matching

我想获取 namesurname 以 'Ib' 开头的数据,但结果行中只有 name 以 'Ib' 开头。

这是我的查询:

select* 
from student
where concat(name,surname) like '%Ib';

您要连接名字和姓氏,因此要检查 "name+surname" 是否以 "Ib" 开头。你想要 where name like 'Ib%' AND surname like 'Ib%'

如果要检索姓名或姓氏以 "Ib" 开头的所有行:

select * 
from student
where name like '%Ib'
or surname like '%Ib';

如果您想要它们都以 "Ib" 开头的行:

select * 
from student
where name like '%Ib'
and surname like '%Ib';