Advertisement
AntonHuretskyi

Добавляем данные в линки

Dec 22nd, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --===========================================================
  2. -- Добавляем данные в линки
  3. --===========================================================
  4.  
  5. INSERT INTO GASANTHONY_GAS_YANDEX_RU__DWH.l_admins(hk_l_admin_id,hk_group_id,hk_user_id,load_dt,load_src)
  6. select
  7.     hash(hg.hk_group_id,hu.hk_user_id),
  8.     hg.hk_group_id,
  9.     hu.hk_user_id,
  10.     now() as load_dt,
  11.     's3' as load_src
  12. from GASANTHONY_GAS_YANDEX_RU__STAGING.groups as g
  13.     left join GASANTHONY_GAS_YANDEX_RU__DWH.h_users as hu on g.admin_id = hu.user_id
  14.     left join GASANTHONY_GAS_YANDEX_RU__DWH.h_groups as hg on g.id = hg.group_id
  15. where hash(hg.hk_group_id,hu.hk_user_id) not in (select hk_l_admin_id from GASANTHONY_GAS_YANDEX_RU__DWH.l_admins);
  16.  
  17.  
  18. INSERT INTO GASANTHONY_GAS_YANDEX_RU__DWH.l_groups_dialogs(hk_l_groups_dialogs,hk_message_id,hk_group_id,load_dt,load_src)
  19. select
  20.     hash(hd.hk_message_id,hg.hk_group_id),
  21.     hd.hk_message_id,
  22.     hg.hk_group_id,
  23.     now() as load_dt,
  24.     's3' as load_src
  25. from GASANTHONY_GAS_YANDEX_RU__STAGING.groups as g
  26.     left join GASANTHONY_GAS_YANDEX_RU__DWH.h_groups as hg on g.id = hg.group_id
  27.     left join GASANTHONY_GAS_YANDEX_RU__STAGING.dialogs as d on g.id = d.message_group
  28.     left join GASANTHONY_GAS_YANDEX_RU__DWH.h_dialogs as hd on d.message_id = hd.message_id
  29. where hash(hd.hk_message_id,hg.hk_group_id) not in (select hk_l_groups_dialogs from GASANTHONY_GAS_YANDEX_RU__DWH.l_groups_dialogs);
  30.  
  31.  
  32. INSERT INTO GASANTHONY_GAS_YANDEX_RU__DWH.l_user_message(hk_l_user_message,hk_user_id,hk_message_id,load_dt,load_src)
  33. select
  34.     hash(hu.hk_user_id, hd.hk_message_id),
  35.     hu.hk_user_id,
  36.     hd.hk_message_id,
  37.     now() as load_dt,
  38.     's3' as load_src
  39. from GASANTHONY_GAS_YANDEX_RU__STAGING.dialogs as d
  40.     left join GASANTHONY_GAS_YANDEX_RU__DWH.h_dialogs as hd on d.message_id = hd.message_id
  41.     left join GASANTHONY_GAS_YANDEX_RU__STAGING.users u on u.id = d.message_from
  42.     left join GASANTHONY_GAS_YANDEX_RU__DWH.h_users as hu on u.id = hu.user_id 
  43. where hash(hu.hk_user_id, hd.hk_message_id) not in (select hk_l_user_message from GASANTHONY_GAS_YANDEX_RU__DWH.l_user_message);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement