sethbgm
sethbgm

Reputation: 13

SQL - Insert into a column depending on the value of another

I'm using phpmyadmin and I want if a value in one column is between 1 and 10, then put a 1 in another column, and if it's between 11 and 20 then put a 2...and so on.

Upvotes: 0

Views: 78

Answers (2)

chetan
chetan

Reputation: 2886

UPDATE table
SET column1 = CEIL(column2/10);

Upvotes: 2

juergen d
juergen d

Reputation: 204756

update your_table
set another_column = case when some_column between 1 and 10
                          then 1
                          when some_column between 11 and 20
                          then 2
                     end

Upvotes: 2

Related Questions