1

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.

1
  • Do you want the count or the sum? Your example is ambiguous, all columns have 1 and you do not clarify why. Commented Jun 2, 2012 at 22:16

1 Answer 1

5
SELECT ID, col1 + col2 + col3 AS colnew FROM my_table
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.