Hi all,
I have a table consists of
Code:
CREATE TABLE /*!32312 IF NOT EXISTS*/ `bilgiler` (
`kayitID` int(11) NOT NULL AUTO_INCREMENT,
`hak_sahibi_id` bigint(15) DEFAULT NULL,
`cinsiyet` tinyint(1) DEFAULT NULL,
`dogumtarihi` date DEFAULT NULL,
`islemtarihi` date DEFAULT NULL,
`tanikodu` varchar(10) DEFAULT NULL,
`tedavi_ili` tinyint(3) DEFAULT NULL,
`dogum_ili` tinyint(3) DEFAULT NULL,
`ikamet_ili` tinyint(3) DEFAULT NULL,
PRIMARY KEY (`kayitID`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin5;
and my SQL query is
Code:
Select bilgiler.hak_sahibi_id,bilgiler.cinsiyet,date_format(bilgiler.dogumtarihi,'%d.%m.%Y') as dtarihi,date_format(bilgiler.islemtarihi, '%d.%m.%Y') as itarihi,(To_days( bilgiler.islemtarihi ) - TO_DAYS( bilgiler.dogumtarihi )) as difference,bilgiler.tanikodu,bilgiler.dogum_ili,bilgiler.ikamet_ili,bilgiler.tedavi_ili,b.repeat from bilgiler INNER JOIN ( SELECT hak_sahibi_id,year(islemtarihi) AS yyyy,COUNT(*) AS 'repeat' from bilgiler group by hak_sahibi_id,year(islemtarihi) ) as b on b.hak_sahibi_id = bilgiler.hak_sahibi_id and b.yyyy = year(bilgiler.islemtarihi) into outfile 'C:/outcome/results.txt' FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\r\n'
As you may understand this query writes the existing fields, calculates the difference of two dates as day and writes as "difference", and also writes how many times a client (hak_sahibi_id) has a record in the year section of field "islemtarihi" as "repeat" and exports the results to text file.
It gives the results perfectly as I want. My problem is the file size is too big. There are 10 million records on this table and code runs very slow. It takes nearly a month with the query.
Is it possible to write a better code makes the same job faster? Is it possible to make changes on MySQL settings to make this query run faster (currently it is using the default settings of MySQL)?
Thanks
telmessos