select LPAD(decode(count(记录编号),0,1,max(to_number(记录编号)+1)),14,'0') 记录编号 from tetdmis
eg:
select decode(dir,1,0,1) from a1_interval
dir 的值是1变为0,是0则变为1
比如我要查询某班男生和女生的数量分别是多少?
通常我们这么写:
select count(*) from 表 where 性别 = 男;
select count(*) from 表 where 性别 = 女;
要想显示到一起还要union一下,太麻烦了
用decode呢,只需要一句话
select sum(decode(性别,男,1,0)),sum(decode(性别,女,1,0)) from 表
eg:
select sum(decode(siteno,'LT',1,0)),sum(decode(siteno,'SZ',1,0)) from facd605;
select sum(case siteno when 'LT' then 1 else 0 end),sum(case siteno when 'SZ' then 1 else 0 end) from facd605;
vinson