Guest User

Untitled

a guest
Mar 16th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.40 KB | None | 0 0
  1. INSERT OVERWRITE TABLE output_table
  2. SELECT  a,b,c
  3.          from_unixtime(unix_timestamp(snapshot_date_time, 'yyyy-MM-dd')) AS snapshot_date_time ,
  4.          count (DISTINCT a)  AS table_c , (
  5.          CASE
  6.                   WHEN (
  7.                                     c>=0 ) THEN count (DISTINCT a)
  8.                   ELSE 0
  9.          END)                     AS dist_a ,
  10.          count (DISTINCT b) AS dist_b ,
  11. FROM     (
  12.                 SELECT a,b,c
  13.                        date_sub(to_date(from_unixtime(unix_timestamp())),117) AS snapshot_date_time
  14.                 FROM   table_a
  15.                 WHERE  to_date(start_date_time)<= date_sub(to_date(from_unixtime(unix_timestamp())),117)
  16.                 AND    (
  17.                               to_date(end_date_time)> date_sub(to_date(from_unixtime(unix_timestamp())),117)
  18.                        OR     end_date_time IS NULL)
  19.                 UNION ALL
  20.                 SELECT a,b,c
  21.                        date_sub(to_date(from_unixtime(unix_timestamp())),118) AS snapshot_date_time ,
  22.                 FROM   table_b
  23.                 WHERE  to_date(start_date_time)<= date_sub(to_date(from_unixtime(unix_timestamp())),118)
  24.                 AND    (
  25.                               to_date(end_date_time)> date_sub(to_date(from_unixtime(unix_timestamp())),118)
  26.                        OR     end_date_time IS NULL)
  27.                ) table_b
  28. GROUP BY a,b,c;
Add Comment
Please, Sign In to add comment