You could use either the TIME type or the INT or DOUBLE/FLOAT/NUMERIC type (depending on the database). Implementation of the type TIME (Mysql):
CREATE TABLE rankingbytime (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(40),
tempo TIME
);
INSERT INTO rankingbytime (nome, tempo) VALUES
('Fulano', '00:32:54'),
('Beltrano', '00:29:52'),
('Ciclano', '00:30:19'),
('Treuslano', '00:31:20'),
('Peuslano', '00:35:14');
SELECT id, nome, tempo FROM rankingbytime ORDER BY tempo ASC;
Exit:
| id | nome | tempo |
|----|-----------|---------------------------|
| 2 | Beltrano | January, 01 1970 00:29:52 |
| 3 | Ciclano | January, 01 1970 00:30:19 |
| 4 | Treuslano | January, 01 1970 00:31:20 |
| 1 | Fulano | January, 01 1970 00:32:54 |
| 5 | Peuslano | January, 01 1970 00:35:14 |
Implementing the type FLOAT (Mysql):
CREATE TABLE rankingbyseconds (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(40),
tempo FLOAT(13,3)
);
INSERT INTO rankingbyseconds (nome, tempo) VALUES
('Fulano', 1974.523),
('Beltrano', 1792.584),
('Ciclano', 1819.287),
('Treuslano', 1880.518),
('Peuslano', 2114.261);
SELECT id, nome, tempo FROM rankingbyseconds ORDER BY tempo ASC;
The decimal places of the type float are the thousandths, if using only second, you can use the field type INT calculating only integers that would represent the number of seconds.
Exit:
| id | nome | tempo |
|----|-----------|----------|
| 2 | Beltrano | 1792.584 |
| 3 | Ciclano | 1819.287 |
| 4 | Treuslano | 1880.518 |
| 1 | Fulano | 1974.523 |
| 5 | Peuslano | 2114.261 |
You can also use the DATETIME type and record the start date and time, and end date and time, this template is for you to search.
Why not use the guy team ? Would the ranking simply be the ordered time decreasing? If yes, just sort in the same query.
– DontVoteMeDown
If you only have one time per player, it should work sort by string. Otherwise you need to use
TIME
as they’re suggesting to you.– bfavaretto
This question is being debated at the goal: http://meta.pt.stackoverflow.com/q/4504/132
– Victor Stafusa