CREATE OR REPLACE VIEW food600.smrtvolyskpol
 AS
 SELECT sk__pol.c_data::bigint AS c_data,
    sk__pol.c_karty::bigint AS c_karty,
    max(sk__uza.uzaverka) AS uzaverka
   FROM food600.sk__pol
     JOIN food600.sk__uza ON sk__pol.c_uzaverka = sk__uza.idriadok
  GROUP BY sk__pol.c_data, sk__pol.c_karty
UNION
 SELECT sk__pol_a.c_data::bigint AS c_data,
    sk__pol_a.c_karty::bigint AS c_karty,
    max(sk__uza.uzaverka) AS uzaverka
   FROM food600.sk__pol_a
     JOIN food600.sk__uza ON sk__pol_a.c_uzaverka = sk__uza.idriadok
  GROUP BY sk__pol_a.c_data, sk__pol_a.c_karty;
