I am working on upwork type project and want to create an update query for bids.
User have free bids(
which he get by default per month
) and pro bids which he can buy for certain amount.
Now if he would apply on any job then I want to update
-1
for job_quota(if it is not 0 already
), then -1
from pro bids in ascending order.
My table structure(in user table):
users
job_quota -------->id
12---------------->53
Buy_bids
id---->no_bids--->amount_paid--->user_id
1-----> 20------------>20---------------> 53
2-----> 20------------>20---------------> 53
3-----> 20------------>20---------------> 53
I have an idea like this, but I do not how to implement it into mysql query:
$query=<<< SQL
update users set job_quota=job_quota-1 if ( job_quota !=0 )
else update buy_bids set no_bids =no_bids-1 where user_id=53
SQL;
Can anyone suggest me how can I achieve it, I am not looking for accurate solution but I need your help and suggestion what should I try to achieve this.
Many Thanks.
Answer:
This is my proposal:
UPDATE users
IF (job_quota NOT IN 0 )
THEN SET job_quota = -1
ELSE (UPDATE buy_bids SET no_bids = no_bids -1
WHERE users.id = 53)
WHERE id= 53
No comments:
Post a Comment