SUM Top 10 records
am 28.09.2010 11:35:45 von Tompkins Neil
--0016364ee89ac4668a04914e91ca
Content-Type: text/plain; charset=ISO-8859-1
Hi
I've a basic table like and want to SUM the top 5 values. For example if I
have
id, rating
0, 10
1, 25
2, 5
3, 10
4, 50
5, 1
6, 15
7, 20
8, 9
I want my query to sum the values
4,50
1,25
7,20
6.15
0,10
Suming a value of 120
Any suggestions on how to achieve this ?
Cheers
Neil
--0016364ee89ac4668a04914e91ca--
Re: SUM Top 10 records
am 28.09.2010 12:28:48 von Tompkins Neil
--0016e64bb7909373db04914f4f77
Content-Type: text/plain; charset=ISO-8859-1
Christoph, this SUMs all values ?
On Tue, Sep 28, 2010 at 11:25 AM, Christoph Boget
> wrote:
> > I've a basic table like and want to SUM the top 5 values. For example if
> I
> > have
> >
> > Any suggestions on how to achieve this ?
> >
>
> SELECT SUM( rating ) as total_rating FROM my-table ORDER BY rating DESC
> LIMIT 5
>
> IIRC, that should work
>
> thnx,
> Christoph
>
>
--0016e64bb7909373db04914f4f77--
Re: SUM Top 10 records
am 28.09.2010 12:35:12 von ekilimchuk
--000e0cd1f8c8574c8004914f6686
Content-Type: text/plain; charset=ISO-8859-1
select `rating`/100+`id` as result from `your_table_name` order by `rating`
desc LIMIT 5;
+--------+
| result |
+--------+
| 4.5000 |
| 1.2500 |
| 7.2000 |
| 6.1500 |
| 0.1000 |
+--------+
2010/9/28 Tompkins Neil
> Hi
>
> I've a basic table like and want to SUM the top 5 values. For example if I
> have
>
> id, rating
> 0, 10
> 1, 25
> 2, 5
> 3, 10
> 4, 50
> 5, 1
> 6, 15
> 7, 20
> 8, 9
>
> I want my query to sum the values
>
> 4,50
> 1,25
> 7,20
> 6.15
> 0,10
>
> Suming a value of 120
>
> Any suggestions on how to achieve this ?
>
> Cheers
> Neil
>
--
Best regards,
Eugene Kilimchuk
--000e0cd1f8c8574c8004914f6686--
Re: SUM Top 10 records
am 28.09.2010 12:45:44 von ekilimchuk
--001517503cc811747104914f8cb9
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: quoted-printable
I'm sorry!
SELECT sum(rating) FROM (SELECT rating FROM your_table_name ORDER BY rating
DESC LIMIT 5) AS result;
2010/9/28 å×ÇÅÎÉ=CA ëÉÌÉÍÞÕË
com>
> select `rating`/100+`id` as result from `your_table_name` order by `ratin=
g`
> desc LIMIT 5;
>
> +--------+
> | result |
> +--------+
> | 4.5000 |
> | 1.2500 |
> | 7.2000 |
> | 6.1500 |
> | 0.1000 |
> +--------+
>
> 2010/9/28 Tompkins Neil
>
>> Hi
>>
>>
>> I've a basic table like and want to SUM the top 5 values. For example i=
f
>> I
>> have
>>
>> id, rating
>> 0, 10
>> 1, 25
>> 2, 5
>> 3, 10
>> 4, 50
>> 5, 1
>> 6, 15
>> 7, 20
>> 8, 9
>>
>> I want my query to sum the values
>>
>> 4,50
>> 1,25
>> 7,20
>> 6.15
>> 0,10
>>
>> Suming a value of 120
>>
>> Any suggestions on how to achieve this ?
>>
>> Cheers
>> Neil
>>
>
>
>
> --
> Best regards,
>
> Eugene Kilimchuk
>
--=20
Best regards,
Eugene Kilimchuk
--001517503cc811747104914f8cb9--