Skip to content

Instantly share code, notes, and snippets.

@dqtweb
Created March 5, 2020 08:42
Show Gist options
  • Save dqtweb/da63dc0b9d46934ac7dfda78f24d1fba to your computer and use it in GitHub Desktop.
Save dqtweb/da63dc0b9d46934ac7dfda78f24d1fba to your computer and use it in GitHub Desktop.
Complex Counts in Hive
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 ("2012-1-12-02", "2012-1-12-03")
GROUP BY
type
ORDER BY
type
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment