That was fast :-)
I tried with avg but this doesn't work as I want.
select avg(count(url_id)) as url_count, user_id from urls_users group by
-> url_id limit 10;
ERROR 1111 (HY000): Invalid use of group function
I don't understand why this happend.
Marnen Laibow-Koser wrote in post #968673:
> Jamal Soueidan wrote in post #968670:
>> Hello,
>>
>> I know this might be out of rails question,
>
> Then don't ask it here.
>
>> but I could not find any
>> other place to ask :D
>
> Apparently you didn't look very hard: http://lmgtfy.com/?q=mysql+forum
>
>>
>> select count(url_id) as url_count, user_id from urls_users group by
>> url_id limit 10;
>> +-----------+---------+
>> | url_count | user_id |
>> +-----------+---------+
>> | 238 | 1 |
>> | 3070 | 2 |
>> | 141 | 3 |
>> | 1 | 7 |
>> | 156 | 8 |
>> | 397 | 11 |
>> | 1 | 15 |
>> | 20 | 16 |
>> | 73 | 17 |
>> | 329 | 18 |
>> +-----------+---------+
>>
>>
>> How do I get the average url_count on all the users in that table based
>> on url_id?
>
> Read about SQL aggregate functions. Also read about
> ActiveRecord::Calculations, which abstracts them in Rails.
>
>>
>> Thanks for help.
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> [email protected]
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.