Donatas Veikutis
Donatas Veikutis

Reputation: 1004

mysql count some column's values in one column

I have that MySQL table:

table
| ID | col1 | col2 | col 3|
  1      1      0      1
  2      0      1      1
  3      1      1      1

how to count all col1, col2, col3 in one column to each row like this?

table
| ID | colnew |
  1      2      
  2      2    
  3      3

Thx.

Upvotes: 1

Views: 178

Answers (1)

eggyal
eggyal

Reputation: 126055

SELECT ID, col1 + col2 + col3 AS colnew FROM my_table

Upvotes: 5

Related Questions