CREATE OR REPLACE VIEW food600.skartyvneprijatychvydajkach
 AS
 SELECT DISTINCT aa.c_partner,
    aa.c_data,
    aa.c_karty
   FROM ( SELECT DISTINCT obraty.c_karty,
            sneprijatevydajky.c_partner,
            obraty.c_data
           FROM food600.obraty
             JOIN food600.sneprijatevydajky ON obraty.c_data = sneprijatevydajky.c_data AND obraty.c_dokl = sneprijatevydajky.c_dokl) aa
     LEFT JOIN food600.food_dat ON aa.c_partner = food_dat.c_stredisk AND aa.c_data = food_dat.c_data
  WHERE NOT (food_dat.id_menu <> ''::bpchar AND "position"(food_dat.pgm_param::text, 'KAN'::text) > 0);
