Content Entry

1.12 将空值替换为实际值

Q: 用非空值替换空值
A: 使用 COALESCE

Oracle,MySQL,PostgreSQL,MSSQL,DB2 (使用COALESCE())
SELECT coalesce(comm, 0)
FROM emp

+-------------------+
| coalesce(comm, 0) |
+-------------------+
| 0 |
| 300 |
| 500 |
| 0 |
| 1400 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
+-------------------+
14 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