Hi all,
I have the table structure of
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;
on a table and I have the following SQL query which creates a field as qnumber and writes the record number according to the islemtarihi(date).
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,(select count(*) from bilgiler t2 where t2.hak_sahibi_id=bilgiler.hak_sahibi_id and t2.islemtarihi <= bilgiler.islemtarihi) as qnumber 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) order by bilgiler.hak_sahibi_id,bilgiler.islemtarihi
My problem with the query is, if there are more than one records on the same islemtarihi output of the query comes like
1
2
4
4
5
So I need to change the query giving the numbers using the islemtarihi,kayitID sections both. So the query will first look at islemtarihi and if the islemtarihi is same, then use kayitID to give the order.
Can anybody help me with that?
Thanks
telmessos