tags:

views:

17

answers:

1

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

+2  A: 

Group By

SELECT user_id, SUM(buy_count)
FROM table
GROUP BY user_id
Dustin Laine
I tried doing that, I get an error message "Cross-database references are not implemented". Strange as user_id is indeed in the table where buy_count is. Ideas?
Roberto
@Roberto: Can you amend your question with the tables and their columns? It would help durilai to write a query that uses specifics. (This may sound obvious but you used your table name in place of `table` didn't you?)
JYelton
@Roberto, you did not specify a table name, so I just used 'table'. See @JYelton comment. I have the most basic syntax there, so update your question and I wil give you an exact query to run.
Dustin Laine