Content Entry

1.13 按模式搜索

Q: 需要返回匹配特定子串或模式的行,比如在部门 10 和 20 中,返回名字有一个 "I", 或者职务中带有 "ER" 的员工行
A: 使用 LIKE 运算符, 通配符 "%"

Oracle,MySQL,PostgreSQL,MSSQL,DB2 (使用 LIKE)
SELECT ename, job
FROM emp
WHERE deptno IN (10, 20)
AND (ename LIKE '%I%' OR job LIKE '%ER')

+--------+-----------+
| ename | job |
+--------+-----------+
| SMITH | CLERK |
| JONES | MANAGER |
| CLARK | MANAGER |
| KING | PRESIDENT |
| MILLER | CLERK |
+--------+-----------+
5 rows in set (0.00 sec)

Tables Used:
for MySQL
http://www.hooto.com/home/rui/doc/archives/5089.html
for PostgreSQL
http://www.hooto.com/home/rui/doc/archives/5090.html

Learn:
SQL Cookbook, by Anthony Molinaro.
Copyright 2006 O'Reilly Media, Inc.

--EOF--

comments loading