在项目第一次遇到decode()函数,简单写一下用法。
1 select count(*),sum(decode(fz.station_class_f, '租用机房', '1', '0')), 2 sum(decode(fz.station_class_f, '自建彩钢板机房', '1', '0')), 3 sum(decode(fz.station_class_f, '自建砖混机房', '1', '0')), 4 sum(decode(fz.station_class_f, '一体化机柜', '1', '0')), 5 sum(decode(fz.station_class_f, 'RRU拉远', '1', '0')), 6 sum(decode(fz.station_class_f, '其他机房', '1', '0')), 7 sum(decode(fz.station_class_f, '无机房', '1', '0')) 8 from wg_jzmb jz, wg_jzfz fz 9 where jz.station_code = fz.station_code 10 and jz.STATION_STAT in ('启用', '暂停支付')
decode(条件1,值1,值2,值3) 如上格式所示
decode(fz.station_class_f, '自建彩钢板机房', '1', '0')
fz.station_class_f字段等于 "自建彩钢板机房" 字符串时,取到值"1",若不等于取到值"0"
再通过sum()函数完成对该数据的累加计算。