2

Quick MySQL problem.

I'm wanting to add multiple columns (column 2) together based one column (column 1) being checked to ensure they hold matching values

Example

Column 1

Team 1 Team 2 Team 3 Team 1 Team 3 Team 2 

Column 2

 1 2 3 1 2 3 

Column 3 (Calculated based on the Values in Column 1 matching)

 2 (Team 1) 4 (Team 2) 6 (Team 3) 

Of course I will begin by doing the following select statement:

SELECT Column 1, Column 2 FROM table WHERE ??? 

After the where is when I don't know what comes next to add the columns together based on the first column holding the same value.

1 Answer 1

1

Looks to me like you just need a simple sum and group by. But I think in your example, Team 2 should have a total of 5, not 4.

SELECT column1,sum(column2) FROM table group by column1 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.