1

I need mysql query that will :

IF (result=win){SELECT dobitak} else if (result=half_win) {SELECT dobitak/2} else if (half_lost) {SELECT stake/2} else{0};
FROM matches 
WHERE id=$id

but i dont know whats the best solution to write query like this.

2

2 Answers 2

3
select case when result ='win' then dobitak
            when result = 'half_win' then dobitak/2
            when result = 'half_lost' then stake/2
            else 0
       end as result
FROM matches 
WHERE id=$id
Sign up to request clarification or add additional context in comments.

Comments

2

I think you can do what you want with a case statement:

select (case when result = win then dobitak
             when result = half_win then dobitak/2
             when half_lost then stake / 2
             else 0
        end)
from matches
where id = $id;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.