标签:
ISNULL是判断是否为NULL
而NULLIF是把值换成NULL
COALESCE是用别的来代替NULL
SELECT employee_id,first_name,last_name,NULLIF (SALES_QUOTA,-1) as Quota
FROM employees
就是把-1变成 NULL
COALESCE(表达式1,表达式2,....表达式n)
从前到后,谁不是NULL就显示谁
Select employee_id,first_name,last_name,
COALESCE ( appt_quota,(Select Min(appt_quota) From employees),0 ) AS quota
From employees
Where department = ‘Marketing‘
附:
ISNULL(check_expression, replacement_value)
NULLIF 用于检查两个表达式,语法:
NULLIF(expression, expression)
例子1:
create table test_table(
IDNUM NUMBER,
CAT VARCHAR2(200),
PRICE NUMBER
);
INSERT INTO test_table VALUES(1,‘‘,10);
INSERT INTO test_table VALUES(2,‘cat1‘,10);
INSERT INTO test_table VALUES(3,‘cat1‘,3);
INSERT INTO test_table VALUES(4,‘cat2‘,11);
INSERT INTO test_table VALUES(5,‘cat2‘,10);
INSERT INTO test_table VALUES(6,‘‘,10);
select
COALESCE(CAT,‘unknown‘),
SUM(PRICE)from test_table GROUP BY CAT;
标签:
原文地址:http://www.cnblogs.com/fffywfn/p/4315388.html