如何将数据库列与字符串匹配

时间:2012-12-07 13:26:05

标签: sql database postgresql

例如,我有一个这样的表:

id |      name      |
--------------------
1  | T              |
2  | Text           |
3  | A              |
4  | Text1 and Text |
5  | Txt            |

,我想用字符串反转匹配列,如下所示:

select * from table_name where %name% like 'Text1 and Text2 and Text3' 

,并获得这些结果:

id | name |
-----------
1  | T | 
2  | Text |
4  | Text1 and Text |

这是怎么回事?

1 个答案:

答案 0 :(得分:3)

尝试:

SELECT *
FROM table_name
WHERE 'Text1 and Text2 and Text3' LIKE '%'||name||'%'

UPD这是我的SQLFiddle示例:SQLFiddle