2

I have a table:

uid_from uid_to count
   x1      x2    3 
   x3      x2    5
   x8      x1    99
   x9      x1    1

And would like to generate a summ table like this:

uid_to   sum
  x1     100
  x2      8

I can do it in PHP, but would rather do it directly in a MySQL query. I should note the table has 700 Million rows.

2
  • 1
    Why does the title to your question say "all distinct values"? Commented Nov 12, 2012 at 17:19
  • @eggyal cuz I wanna sum all the distinct uid_to values. Thought about the problem wrong. Commented Nov 12, 2012 at 17:20

1 Answer 1

3
select uid_to, sum(count) as sum
from your_table
group by uid_to
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. do you think this will end in within a reasonable time?
Yes. If not take a look at the indexes of your table.

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.