0

I need to

SELECT amount FROM table WHERE type='1' AND type='2' AND type'3'

Depending on the types, I need them to be pulled into different columns.

For example,

IF type=1 THEN amount1 IF type=2 THEN amount2 IF type=3 THEN amount3.

Is it possible to this in one statement?

1

This is one of the ways

SELECT

CASE WHEN `amount`='type 1' then `amount` end as `amount1`,

CASE WHEN `amount`='type 2' then `amount` end as `amount2`,

CASE WHEN `amount`='type 3' then `amount` end as `amount3`

FROM db.tablename;

Ex:

SELECT

CASE WHEN amount=1000 then amount end as amount1,

CASE WHEN amount=2000 then amount end as amount2,

CASE WHEN amount=3000 then amount end as amount3

FROM db.test;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.