Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT OVERWRITE TABLE output_table
- SELECT a,b,c
- from_unixtime(unix_timestamp(snapshot_date_time, 'yyyy-MM-dd')) AS snapshot_date_time ,
- count (DISTINCT a) AS table_c , (
- CASE
- WHEN (
- c>=0 ) THEN count (DISTINCT a)
- ELSE 0
- END) AS dist_a ,
- count (DISTINCT b) AS dist_b ,
- FROM (
- SELECT a,b,c
- date_sub(to_date(from_unixtime(unix_timestamp())),117) AS snapshot_date_time
- FROM table_a
- WHERE to_date(start_date_time)<= date_sub(to_date(from_unixtime(unix_timestamp())),117)
- AND (
- to_date(end_date_time)> date_sub(to_date(from_unixtime(unix_timestamp())),117)
- OR end_date_time IS NULL)
- UNION ALL
- SELECT a,b,c
- date_sub(to_date(from_unixtime(unix_timestamp())),118) AS snapshot_date_time ,
- FROM table_b
- WHERE to_date(start_date_time)<= date_sub(to_date(from_unixtime(unix_timestamp())),118)
- AND (
- to_date(end_date_time)> date_sub(to_date(from_unixtime(unix_timestamp())),118)
- OR end_date_time IS NULL)
- ) table_b
- GROUP BY a,b,c;
Add Comment
Please, Sign In to add comment