page id
1 a1
1 a2
1 a3
2 a4
2 a5
2 a6
3 a7
3 a8
3 a9
`
我需要知道的是如何自动生成一个数字页面'像那样 ?所以这意味着a1 a2 a3在第1页,a4 a5 a6在第2页,a7 a8 a9在第3页
我尝试过使用此查询
set @num:=0;
select id, @num:=@num+1 `Row` from promos;
然后结果是
page id
1 a1
2 a2
3 a3
4 a4
5 a5
6 a6
7 a7
8 a8
9 a9
`
答案 0 :(得分:1)
试试这个
SELECT CEIL(MID(id,2)/3) as pages,id FROM promos;
答案 1 :(得分:1)
来自MySQL文档:
CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
) ENGINE=MyISAM;
INSERT INTO animals (grp,name) VALUES
('mammal','dog'),('mammal','cat'),
('bird','penguin'),('fish','lax'),('mammal','whale'),
('bird','ostrich');
+--------+----+---------+
| grp | id | name |
+--------+----+---------+
| fish | 1 | lax |
| mammal | 1 | dog |
| mammal | 2 | cat |
| mammal | 3 | whale |
| bird | 1 | penguin |
| bird | 2 | ostrich |
+--------+----+---------+
在此处阅读更多内容 - Using AUTO_INCREMENT