Erp100论坛's Archiver

xiangzhao 发表于 2008-7-12 21:14

请求一条sql语句

如果A字段为空,就取B字段的值,如果B字段的值为空,就取c字段的值,如果c字段的值为空,就取d字段的值

字段
A    B    C    D
1    -    -  -
-   2    -  -
-   -   3  -
-  -    -  4
1   2     -  -
1   2     3   -

结果;
1
2
3
4
1
1

xiangzhao 发表于 2008-7-12 21:14

select coalesce(a,b,c,d) from dual;

COALESCE returns the first non-null expr in the expression list. At least one expr must not be the literal NULL. If all occurrences of expr evaluate to null, then the function returns null.

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2007 Comsenz Inc.