Roberto
Roberto

Reputation: 2990

Frequency Table by user in SQL

Very basic SQL question (DB is MySQL):

I want a table of number of transactions by users.

User ID   Transaction count
1         43
2         213
3         0
4         23
5         0

In a table I have the two relevant records (user_id and buy_count).

How could I get the table I want?

Thanks,

Roberto

Upvotes: 1

Views: 811

Answers (1)

Dustin Laine
Dustin Laine

Reputation: 38503

Group By

SELECT user_id, SUM(buy_count)
FROM table
GROUP BY user_id

Upvotes: 2

Related Questions