count(*)和count(1):对表中行数进行统计计算,包含null值。
count(某字段):对表中该字段的行数进行统计,不包含null值。如果出现空字符串,同样会进行统计。
SELECT
type
, count(*)
, count(DISTINCT u)
, count(CASE WHEN plat=1 THEN u ELSE NULL END)
, count(DISTINCT CASE WHEN plat=1 THEN u ELSE NULL END)
, count(CASE WHEN (type=2 OR type=6) THEN u ELSE NULL END)
, count(DISTINCT CASE WHEN (type=2 OR type=6) THEN u ELSE NULL END)
FROM
t
WHERE
dt in ("2018-05-20", "2018-05-21")
GROUP BY
type
ORDER BY
type
;