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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.