在项目第一次遇到decode()函数,简单写一下用法。

 select count(*),sum(decode(fz.station_class_f, '租用机房', '', '')),
sum(decode(fz.station_class_f, '自建彩钢板机房', '', '')),
sum(decode(fz.station_class_f, '自建砖混机房', '', '')),
sum(decode(fz.station_class_f, '一体化机柜', '', '')),
sum(decode(fz.station_class_f, 'RRU拉远', '', '')),
sum(decode(fz.station_class_f, '其他机房', '', '')),
sum(decode(fz.station_class_f, '无机房', '', ''))
from wg_jzmb jz, wg_jzfz fz
where jz.station_code = fz.station_code
and jz.STATION_STAT in ('启用', '暂停支付')

decode(条件1,值1,值2,值3)  如上格式所示

decode(fz.station_class_f, '自建彩钢板机房', '1', '0')
fz.station_class_f字段等于 "自建彩钢板机房" 字符串时,取到值"1",若不等于取到值"0"
再通过sum()函数完成对该数据的累加计算。
05-08 15:14