[MySQL] RANKING
ÆäÀÌÁö 1 Áß 1
[MySQL] RANKING
CREATE TABLE shop (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
food VARCHAR(32),
gold DECIMAL,
point int(5)
);
INSERT INTO shop
VALUES (NULL, 'apple', 12.75, 10), (NULL, 'orange', 1.89, 3), (NULL, 'pear', 19.23, 6)
, (NULL, 'banana', 4.25, 7), (NULL, 'cherry', 12.75, 2), (NULL, 'plum', 23.15, 5);
SET @rank=0;
SELECT @rank:=@rank+1 AS rank, food, gold, point
FROM shop
ORDER BY gold DESC, point DESC
;
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
food VARCHAR(32),
gold DECIMAL,
point int(5)
);
INSERT INTO shop
VALUES (NULL, 'apple', 12.75, 10), (NULL, 'orange', 1.89, 3), (NULL, 'pear', 19.23, 6)
, (NULL, 'banana', 4.25, 7), (NULL, 'cherry', 12.75, 2), (NULL, 'plum', 23.15, 5);
SET @rank=0;
SELECT @rank:=@rank+1 AS rank, food, gold, point
FROM shop
ORDER BY gold DESC, point DESC
;
Admin- Admin
- °Ô½Ã¹° °¹¼ö : 380
Age : 54
Registration date : 2008-08-09
Character sheet
test:
Re: [MySQL] RANKING
[°á°ú]
+------+---------+------+-------+
| rank | food | gold | point |
+------+---------+------+-------+
| 1 | plum | 23 | 5 |
| 2 | pear | 19 | 6 |
| 3 | apple | 13 | 10 |
| 4 | cherry | 13 | 2 |
| 5 | banana | 4 | 7 |
| 6 | orange | 2 | 3 |
+------+---------+------+-------+
6 rows in set
+------+---------+------+-------+
| rank | food | gold | point |
+------+---------+------+-------+
| 1 | plum | 23 | 5 |
| 2 | pear | 19 | 6 |
| 3 | apple | 13 | 10 |
| 4 | cherry | 13 | 2 |
| 5 | banana | 4 | 7 |
| 6 | orange | 2 | 3 |
+------+---------+------+-------+
6 rows in set
Admin- Admin
- °Ô½Ã¹° °¹¼ö : 380
Age : 54
Registration date : 2008-08-09
Character sheet
test: