Jump to content

strange mysql running variables


chaiwei

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.