1、按照区域编码分组查询区域编码、IPTV_NBR不为空的数量、ACC_NBR不为空的数量、所有用户数量
SELECT
AREA_CODE,
SUM (
CASE
WHEN IPTV_NBR IS NULL or IPTV_NBR = '' THEN
0
ELSE
1
END
),
SUM (
CASE
WHEN ACC_NBR IS NULL or ACC_NBR = '' THEN
0
ELSE
1
END
),
COUNT (*)
FROM
GAT_SQMS.GAT_SQMS_BAND_IPTV_VIEW
GROUP BY
AREA_CODE;
2、使用sum条件查询
查询IPTV_NBR不为空的数量
SUM (
CASE
WHEN IPTV_NBR IS NULL or IPTV_NBR = '' THEN
0
ELSE
1
END
)
SUM里边使用CASE WHEN 语句,
当IPTV_NBR IS NULL 为0,ELSE 为1
SELECT
AREA_CODE,
SUM (
CASE
WHEN IPTV_NBR IS NULL or IPTV_NBR = '' THEN
0
ELSE
1
END
),
SUM (
CASE
WHEN ACC_NBR IS NULL or ACC_NBR = '' THEN
0
ELSE
1
END
),
COUNT (*)
FROM
GAT_SQMS.GAT_SQMS_BAND_IPTV_VIEW
GROUP BY
AREA_CODE;
2、使用sum条件查询
查询IPTV_NBR不为空的数量
SUM (
CASE
WHEN IPTV_NBR IS NULL or IPTV_NBR = '' THEN
0
ELSE
1
END
)
SUM里边使用CASE WHEN 语句,
当IPTV_NBR IS NULL 为0,ELSE 为1