Thursday, January 9, 2014

Hive - A QL for NULL

SELECT count(distinct s1.uu_id)
FROM (
    SELECT distinct uu_id FROM table1
    WHERE dt >= "2014-01-01" AND dt < "2014-01-02"
   ) s1
   LEFT OUTER JOIN (
    SELECT distinct uu_id FROM table1
    WHERE dt >= "2014-01-01" AND dt < "2014-01-02"
    AND activity = 'spend'
) s2
  ON (s1.uu_id = s2.uu_id)
JOIN (
    SELECT distinct uu_id FROM table1
    WHERE dt = "2014-01-02"
    AND activity = 'spend'
) s3
  ON (s1.uu_id = s3.uu_id)
WHERE s2.uu_id IS NULL

No comments:

Post a Comment