0

If I have a table containing a column of text and a column of integers, how can I sum the integers specific to each text entry? Example:

text1 | 4
text2 | 2
text3 | 5
text2 | 3
text1 | 2

I want to do: SELECT Text,SUM(Number) FROM TABLE

However, that sums all the numbers together (text1 | 16). How can I sum the numbers with each text entry independently?( text1 | 6 text2 | 5 text3 | 5 )

1 Answer 1

4

Have a look at the GROUP BY clause: http://www.sqlite.org/lang_select.html#resultset

Example usage:

SELECT   mycolumn, SUM(myothercolumn) 
FROM     mytable
GROUP BY mycolumn
ORDER BY mycolumn;
Sign up to request clarification or add additional context in comments.

1 Comment

I think I had done GROUP BY on "myothercolumn" and ORDER BY separately, but never though to combine them. You're exactly right in the example you gave back. Thank you kindly :)

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.