chaiwei Posted January 7, 2010 Share Posted January 7, 2010 Hi, Anything wrong with this sql? SET @susm =0; SELECT rj.job_id, date_format( max( rjs.datestamp ) , '%Y-%m' ) AS filled_date, @susm := @susm + ( no_of_vacancy ) , no_of_vacancy, COUNT( rjs.status ) AS cnt FROM resume_job rj, resume_application_status rjs WHERE rj.job_id = rjs.job_id AND rjs.status = 'accepted' AND rj.job_type = 'p' GROUP BY rj.job_id HAVING cnt = rj.no_of_vacancy AND filled_date = '2009-11' it returns me 203,204,205 Why the first number become 203? then the second 204? the no_of_vacancy should be equals to 1 Is it because of the group by function? 3891 2009-11 203 1 1 3900 2009-11 204 1 1 3896 2009-11 205 1 1 but if I changed the @susm := @susm + ( no_of_vacancy ) to @susm := @susm + 1 it works normally. 3891 2009-11 1 1 1 3900 2009-11 2 1 1 3896 2009-11 3 1 1 Link to comment https://forums.phpfreaks.com/topic/187561-strange-mysql-running-variables/ Share on other sites More sharing options...
chaiwei Posted January 7, 2010 Author Share Posted January 7, 2010 even I change to this , it works correctly SET @susm =0; SELECT rj.job_id, date_format( max( rjs.datestamp ) , '%Y-%m' ) AS filled_date, @susm := 1 + ( no_of_vacancy ) , no_of_vacancy, COUNT( rjs.status ) AS cnt FROM resume_job rj, resume_application_status rjs WHERE rj.job_id = rjs.job_id AND rjs.status = 'accepted' AND rj.job_type = 'p' GROUP BY rj.job_id HAVING cnt = rj.no_of_vacancy AND filled_date = '2009-11' job_id filled_date @susm:=1+no_of_vacancy no_of_vacancy cnt 3891 2009-11 2 1 1 3896 2009-11 2 1 1 3900 2009-11 2 1 1 Link to comment https://forums.phpfreaks.com/topic/187561-strange-mysql-running-variables/#findComment-990271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.