V1rtua1An0ma1y
V1rtua1An0ma1y

Reputation: 627

Aggregate Functions in SQLite

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 )

Upvotes: 0

Views: 2411

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169414

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;

Upvotes: 4

Related Questions