关于count(case when col_name='a' then 'b' else)

来源:百度知道 编辑:UC知道 时间:2024/06/25 15:36:27
col col1
a 3
c r
v 3

select count(case when col='a' then 'b' else) counts from tab_name返回什么? 是1吗? 请详细解释 :)

你的sql没有写对。
正常的应该是:
select count(case when col='a' then 'b' end) counts from tab_name;
*****************************************
log
*****************************************
[TEST@ora1] SQL>select * from test4;

COL COL1
--- ----
a 3
c r
v 3

[TEST@ora1] SQL>select count(case when col='a' then 'b' else) counts from test4;

select count(case when col='a' then 'b' else) counts from test4
*
ERROR at line 1:
ORA-00936: missing expression

[TEST@ora1] SQL>select count(case when col='a' then 'b' end) counts from test4;

COUNTS
----------
1
********************
原因:
********************
[TEST@ora1] SQL>select nvl(case when col='a' then 'b' end,'NULL') from test4;

NVL(
---