[MySQL] RANKING

이전 주제 보기 다음 주제 보기 Go down

[MySQL] RANKING

올리기 by Admin on 2009-10-31, 4:57 am

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
;

Admin
Admin

게시물 갯수 : 380
Age : 47
Registration date : 2008-08-09

Character sheet
test:

사용자 정보 보기 http://study4u.justgoo.com

위로 Go down

Re: [MySQL] RANKING

올리기 by Admin on 2009-10-31, 5:01 am

[결과]
+------+---------+------+-------+
| 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 : 47
Registration date : 2008-08-09

Character sheet
test:

사용자 정보 보기 http://study4u.justgoo.com

위로 Go down

이전 주제 보기 다음 주제 보기 위로


 
Permissions in this forum:
답글을 올릴 수 없습니다