PSQL - 如何选择两列的组合?

时间:2014-07-21 11:05:42

标签: postgresql ibatis

我有一个包含列的表格如下:

User
   id integer;
   firstName varchar;
   lastName varchar;
   employee_id integer;

现在表格中的数据如下:

User(1,"John","Dake",123)
User(2,"John","Daniel",124)
User(3,"Richard","Johnson",125)
User(4,"Peter","Federo",126)
User(5,"George","Daniel",127)

我需要对名字 - 姓氏的组合进行搜索。因此,我们假设搜索查询是" John D "。然后输出应该是前两行。是否可以编写此类查询而无需创建新视图或表来获取输出?

1 个答案:

答案 0 :(得分:0)

试试这个

SELECT * FROM demo WHERE firstName||' '||lastName LIKE '%John D%'

SQL FIDDLE