2

Below is the table I have created, my goal is to get the sum of the value depending of each person has, and exclude any username duplicate.

username | value
Bob          5
Vicky        10
Bob          12

Desire results:

username | value
Bob          17
Vicky        10

4 Answers 4

8

This is what the GROUP BY clause do, use GROUP BY username with SUM(value):

SELECT username, SUM(value)
FROM tablename
GROUP BY username;

When you add a GROUP BY clause, rows that have the same values in the list of columns you specify in it, will be gathered into a group of unique values. For the other columns that are not listed in the GROUP BY clause, the aggregate function will be applied to it, the SUM(value) in the query above.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

SELECT T.username, SUM(T.value) AS value
FROM your_table_name T
WHERE T.username IS NOT NULL
GROUP BY T.username 

Comments

0

Try This one

SELECT username, SUM(value) as val FROM tablename GROUP BY username;

Comments

0

Use the following query:

SELECT url, SUM(pos) FROM import_images GROUP BY url

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.