MySQL Forums
Forum List  »  Newbie

Re: SUM problem.
Posted by: Jay Alverson
Date: March 12, 2009 09:52AM

Something like this, or is it too simplistic ?

mysql> 
mysql> select version();
+---------------------+
| version()           |
+---------------------+
| 5.0.67-community-nt | 
+---------------------+
1 row in set (0.00 sec)

mysql> 
mysql> use test;
Database changed
mysql> 
mysql> drop table if exists top10;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> create table top10 (
    -> player smallint,
    -> points smallint);
Query OK, 0 rows affected (0.08 sec)

mysql> 
mysql> insert into top10 values
    -> (1,1),
    -> (2,2),
    -> (3,3),
    -> (4,4),
    -> (5,5),
    -> (6,6),
    -> (7,7),
    -> (8,8),
    -> (9,9),
    -> (10,10);
Query OK, 10 rows affected (0.00 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> 
mysql> select * from top10 order by points desc limit 8;
+--------+--------+
| player | points |
+--------+--------+
|     10 |     10 | 
|      9 |      9 | 
|      8 |      8 | 
|      7 |      7 | 
|      6 |      6 | 
|      5 |      5 | 
|      4 |      4 | 
|      3 |      3 | 
+--------+--------+
8 rows in set (0.00 sec)

mysql> select points into @lastpoints from top10 order by points desc limit 7,1;
Query OK, 1 row affected (0.00 sec)

mysql> select @lastpoints;
+-------------+
| @lastpoints |
+-------------+
| 3           | 
+-------------+
1 row in set (0.02 sec)

mysql> select sum(points) from top10 where points >= @lastpoints;
+-------------+
| sum(points) |
+-------------+
|          52 | 
+-------------+
1 row in set (0.00 sec)

mysql> 
mysql> notee
>

Thanks, Jay

Options: ReplyQuote


Subject
Written By
Posted
March 12, 2009 03:29AM
Re: SUM problem.
March 12, 2009 09:52AM
March 13, 2009 07:10PM
March 13, 2009 11:10PM
March 14, 2009 04:01PM
March 14, 2009 06:40PM
March 15, 2009 07:54AM
March 15, 2009 10:41AM
March 15, 2009 10:35PM
March 16, 2009 09:33AM
March 16, 2009 09:52AM
March 16, 2009 02:46PM
March 16, 2009 04:15PM
March 17, 2009 02:11PM
March 17, 2009 05:03PM
March 17, 2009 06:31PM
March 17, 2009 10:17PM
March 18, 2009 06:03AM
March 15, 2009 05:41PM
March 15, 2009 07:14PM
March 16, 2009 08:34AM
March 18, 2009 12:52AM
March 21, 2009 05:58AM
March 21, 2009 11:13AM
March 22, 2009 05:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.