改编@SteveCav s Solutions to UNION
with the original query:
SELECT d.*
FROM data d
JOIN (
SELECT MIN(id) lowest_id
FROM data
WHERE date = 20/8/2010
) dt ON (dt.lowest_id - 1 = d.id)
UNION
SELECT *
FROM data
WHERE date = 20/8/2010 ;
测试案例(第3类测试):
CREATE TABLE data (id int, date date, name varchar(10));
INSERT INTO data VALUES (1, 19/8/2010 , John );
INSERT INTO data VALUES (2, 19/8/2010 , Mary );
INSERT INTO data VALUES (3, 20/8/2010 , Peter );
INSERT INTO data VALUES (4, 20/8/2010 , Bert );
INSERT INTO data VALUES (5, 20/8/2010 , Ernie );
结果:
id date name
---------- ---------- ----------
2 19/8/2010 Mary
3 20/8/2010 Peter
4 20/8/2010 Bert
5 20/8/2010 Ernie
假设通过“前行”,你打算使用以前的<代码>id值。