1

Temat: tabela przestawna - crosstab cz2

DROP TABLE IF EXISTS sde.wod_gat_drzew_dane;
CREATE TABLE sde.wod_gat_drzew_dane (
  id_wod_gat_drzew_dane serial NOT NULL,
  id_wod_gat_drzew integer NOT NULL,
  m3 real NULL,
  czesc1 real NULL,
  czesc2 real NULL,
  czesc3 real NULL,
  id_zablokowany integer NOT NULL DEFAULT 2,
  CONSTRAINT wod_gat_drzew_dane_pkey PRIMARY KEY (id_wod_gat_drzew_dane)
)
WITH (OIDS=FALSE);
ALTER TABLE sde.wod_gat_drzew_dane OWNER TO mg;

GRANT SELECT, UPDATE, INSERT, REFERENCES, TRIGGER ON TABLE sde.wod_gat_drzew_dane TO mg;

insert into sde.wod_gat_drzew_dane values (1, 1, 2.17, 1.1, 1.17, 0, 2);
insert into sde.wod_gat_drzew_dane values (2, 1, 3.13, 1, 2, 0.13, 2);
insert into sde.wod_gat_drzew_dane values (3, 1, 1.81, 0, 1, 0.81, 2);
insert into sde.wod_gat_drzew_dane values (4, 2, 0.67, 0.2, 0, 0.47, 2);
insert into sde.wod_gat_drzew_dane values (5, 2, 4.41, 2, 2, 0.41, 2);
insert into sde.wod_gat_drzew_dane values (6, 2, 2.21, 0, 1, 1.21, 2);
insert into sde.wod_gat_drzew_dane values (7, 3, 1.11, 0.5, 0.61, 0, 2);
insert into sde.wod_gat_drzew_dane values (8, 3, 1.12, 0.5, 0, 0.62, 1);
insert into sde.wod_gat_drzew_dane values (9, 3, 2.34, 1, 1, 0.34, 1);
insert into sde.wod_gat_drzew_dane values (10, 4, 2.1, 1, 0.5, 0.6, 1);
insert into sde.wod_gat_drzew_dane values (11, 4, 3.1, 2.1, 1, 0, 2);
insert into sde.wod_gat_drzew_dane values (12, 4, 4.1, 1, 2, 1.1, 2);
insert into sde.wod_gat_drzew_dane values (13, 5, 5.1, 0.1, 2, 3, 2);
insert into sde.wod_gat_drzew_dane values (14, 5, 6.1, 0.1, 3, 3, 2);
insert into sde.wod_gat_drzew_dane values (15, 5, 7.1, 0.1, 3, 4, 2);
insert into sde.wod_gat_drzew_dane values (16, 6, 8.1, 0, 0, 8.1, 2);
insert into sde.wod_gat_drzew_dane values (17, 6, 9.1, 9.1, 0, 0, 2);
insert into sde.wod_gat_drzew_dane values (18, 6, 3.2, 1.1, 1.1, 1, 2);
insert into sde.wod_gat_drzew_dane values (19, 7, 6.4, 2, 2, 2.4, 2);
insert into sde.wod_gat_drzew_dane values (20, 7, 7.5, 3, 3, 1.5, 2);
insert into sde.wod_gat_drzew_dane values (21, 7, 5.8, 1, 1, 3.8, 2);
insert into sde.wod_gat_drzew_dane values (22, 7, 5.9, 2, 2, 1.9, 2);
insert into sde.wod_gat_drzew_dane values (23, 8, 2.1, 1, 0.5, 0.6, 2);
insert into sde.wod_gat_drzew_dane values (24, 8, 3.1, 2, 1.1, 0, 2);
insert into sde.wod_gat_drzew_dane values (25, 8, 4.1, 0, 2, 2.1, 2);
insert into sde.wod_gat_drzew_dane values (26, 9, 2.4, 1, 0, 1.4, 2);
insert into sde.wod_gat_drzew_dane values (27, 9, 2.2, 0.7, 1.5, 0, 2);
insert into sde.wod_gat_drzew_dane values (28, 9, 1.7, 1, 0.7, 0, 2);
insert into sde.wod_gat_drzew_dane values (29, 10, 2.8, 0, 1.8, 1, 2);
insert into sde.wod_gat_drzew_dane values (30, 10, 2.31, 1, 0, 1.31, 1);
insert into sde.wod_gat_drzew_dane values (31, 10, 1.9, 0.6, 1.3, 0, 2);

--#######################--

DROP TABLE IF EXISTS sde.wod_gat_drzew;
CREATE TABLE sde.wod_gat_drzew (
  id_wod_gat_drzew serial NOT NULL,
  id_wod integer NOT NULL,
  id_gat_drzew integer NOT NULL,
  CONSTRAINT wod_gat_drzew_pkey PRIMARY KEY (id_wod_gat_drzew)
)
WITH (OIDS=FALSE);
ALTER TABLE sde.wod_gat_drzew OWNER TO mg;

GRANT ALL ON TABLE sde.wod_gat_drzew TO mg;

insert into sde.wod_gat_drzew values (1, 1, 2);
insert into sde.wod_gat_drzew values (2, 1, 5);
insert into sde.wod_gat_drzew values (3, 1, 8);
insert into sde.wod_gat_drzew values (4, 2, 7);
insert into sde.wod_gat_drzew values (5, 2, 12);
insert into sde.wod_gat_drzew values (6, 3, 11);
insert into sde.wod_gat_drzew values (7, 3, 12);
insert into sde.wod_gat_drzew values (8, 4, 1);
insert into sde.wod_gat_drzew values (9, 4, 2);
insert into sde.wod_gat_drzew values (10, 4, 7);

--#######################--

DROP TABLE IF EXISTS wod;
CREATE TABLE wod (
  id_wod serial NOT NULL,
  id_obwod_ochr integer NOT NULL,
  rok integer NOT NULL,
  zatwierdzony character varying(3) DEFAULT 'NIE',
  CONSTRAINT wod_pkey PRIMARY KEY (id_wod)
)
WITH (OIDS=FALSE);
ALTER TABLE wod OWNER TO mg;

GRANT SELECT, UPDATE, INSERT, REFERENCES, TRIGGER ON TABLE wod TO mg;

insert into wod values (1, 2, 2012, 'TAK');
insert into wod values (2, 6, 2012, 'TAK');
insert into wod values (3, 12, 2012, 'NIE');
insert into wod values (4, 2, 2012, 'TAK');

Ostatnio edytowany przez przesq (2012-08-27 08:23:31)