时间:2021-07-01 10:21:17 帮助过:148人阅读
初始化表结构 DROP TABLE IF EXISTS `data` ; CREATE TABLE `data` ( `dates` varchar ( 255 ) CHARACTER SET utf8 DEFAULT NULL , `id` int ( 11 ) DEFAULT NULL , `result` varchar ( 255 ) CHARACTER SET utf8 DEFAULT NULL ); INSERT INTO `data` ( `dat
DROP TABLE IF EXISTS `data`;
CREATE TABLE `data` (
`dates` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
`id` int(11) DEFAULT NULL,
`result` varchar(255) CHARACTER SET utf8 DEFAULT NULL
);
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015109101', 1, '胜');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015110101', 2, '负');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015109101', 3, '负');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015109101', 4, '胜');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015110101', 5, '胜');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015109101', 6, '负');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015109101', 7, '胜');
INSERT INTO `data` (`dates`, `id`, `result`) VALUES ('2015110101', 8, '负');
select @rownum:=@rownum+1 AS rownum,id,dates
from
`data`,(SELECT @rownum:=0) r
ORDER BY dates;
SELECT rownum,id
from
(select @rownum:=@rownum+1 AS rownum,id,dates
from
`data`,(SELECT @rownum:=0) r
ORDER BY dates)b
WHERE id =2;
获取你有更好的方法在mysql中来实现Rownum(),欢迎不吝赐教。