Marsal
Marsal

Reputation: 1

Cast into BIT Datatype while changing values

What I want to do is to specify in the query that I want to turn any rating lower than 2 into a 0 and turn any rating greater than 2 into 1 while alltogether casting into BIT datatype

select name,lastname from table_name;

Upvotes: 0

Views: 35

Answers (1)

GMB
GMB

Reputation: 222432

You can use a case expression:

case when rating > 2 then 1 else 0 end as rating 

In MySQL, this can be simplified as just:

(rating > 2) as rating 

In your query:

select (rating > 2) as rating, name, lastname
from table_name

Upvotes: 1

Related Questions