15 maj 2008

Obróbka pliku z danymi


LOAD DATA INFILE 'D:\\dane_dane.txt' INTO TABLE dane

ALTER TABLE dane ADD KOLOR_N VARCHAR(255) AFTER ksiazka
ALTER TABLE dane_kolory ADD KOLOR_N VARCHAR(255) AFTER ksiazka
update dane set KOLOR_N = Replace (KOLOR, ' ', '')
create table kolory (KOLOR_N VARCHAR(255), cnt int(10));
insert into kolory (KOLOR_N, cnt) select KOLOR_N, count(*) from dane group by KOLOR_N
create table kolory_w1 (KOLOR_N VARCHAR(255), cnt int(10));
insert into kolory_w1 (KOLOR_N, cnt) select KOLOR_N, cnt from kolory WHERE kolory.cnt > 1
insert into dane_kolory select dane.* from kolory_w1 LEFT JOIN dane ON kolory_w1.KOLOR_N = dane.KOLOR_N

alter table dane add index KOLOR_N_idx (KOLOR_N)
alter table kolory_w1 add index KOLOR_N_idx (KOLOR_N)
select dane_kolory.* into outfile 'd:\\dane_dane2.txt' from dane_kolory;