- 論壇徽章:
- 0
|
http://dev.mysql.com/doc/refman/ ... l#function_coalesce
COALESCE(value,...)
Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
mysql> SELECT COALESCE(NULL,1);
-> 1
mysql> SELECT COALESCE(NULL,NULL,NULL);
-> NULL
顯示第一個(gè)不是NULL的值。
多個(gè)參數(shù)也一樣。
mysql> select coalesce(1,2,3,4) ;
+-------------------+
| coalesce(1,2,3,4) |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.00 sec)
mysql> select coalesce(null,2,3,4) ;
+----------------------+
| coalesce(null,2,3,4) |
+----------------------+
| 2 |
+----------------------+
1 row in set (0.00 sec)
mysql> select coalesce(null,null,3,4) ;
+-------------------------+
| coalesce(null,null,3,4) |
+-------------------------+
| 3 |
+-------------------------+
1 row in set (0.00 sec) |
|