0

I'm wanting to change a select value depending on the where clause. Is something like the following possible in any way?

SELECT b
FROM table
WHERE 
    IF date = '2016-03-24'
        b = 1
    ELSE IF date > date '2016-03-24' - 7 AND date < '2016-03-24'
        b = 2
    ELSE
        b = 1
ORDER BY date
LIMIT 1

1 Answer 1

1

Use CASE WHEN:

SELECT CASE WHEN date = '2016-03-24' THEN 1
            WHEN date > '2016-03-17' AND date < '2016-03-24' THEN 2
            ELSE 1
       END AS b
FROM table
ORDER BY b
LIMIT 1
Sign up to request clarification or add additional context in comments.

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.