CREATE TABLE afa_torzs
(
  ervdatum date NOT NULL,
  csoportkod character(1) NOT NULL,
  futesafa character(2),
  melegvizafa character(2),
  futesalapdijafa character(2),
  kozosafa character(2),
  hidegafa character(2),
  c_userid character varying(15),
  c_date date,
  c_time time without time zone,
  e_userid character varying(15),
  e_date date,
  e_time time without time zone,
  CONSTRAINT afa_torzs_pkey PRIMARY KEY (ervdatum, csoportkod)
)
WITHOUT OIDS;

INSERT INTO afa_torzs (ervdatum, csoportkod, futesafa, melegvizafa, futesalapdijafa, kozosafa, hidegafa) 
  (SELECT ervdatum, 'L' as kod, L_DIJAFA, L_VIZAFA, B_EGYAFA, L_LIFTAFA, L_EGYAFA FROM afa);
INSERT INTO afa_torzs (ervdatum, csoportkod, futesafa, melegvizafa, futesalapdijafa, kozosafa, hidegafa) 
  (SELECT ervdatum, 'I' as kod, i_AFA, i_VIZAFA, B_EGYAFA, l_LIFTAFA, l_EGYAFA FROM afa);
INSERT INTO afa_torzs (ervdatum, csoportkod, futesafa, melegvizafa, futesalapdijafa, kozosafa, hidegafa) 
  (SELECT ervdatum, 'K' as kod, B_AFA, B_VIZAFA, B_EGYAFA, L_LIFTAFA, L_EGYAFA FROM afa);