Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

MySQL使用字段自定义字段排序后,查找上一篇下一篇,但是查找上一篇不正确,怎么办?

这是正常排序情况:

image

以下是查找上一篇的sql:

SELECT * FROM article WHERE sort >= 0 AND time >= '2020-10-25 14:15:56' ORDER BY sort DESC,time DESC;

得到结果正确 如下显示:
image

附上表sql结构 如下:

INSERT INTO cs_test.article (id, title, content, sort, time`) VALUES ('1', '标题一', '内容1', '0', '2020-10-25 14:14:28');
INSERT INTO cs_test.article (id, title, content, sort, time) VALUES ('2', '标题二', '内容2', '0', '2020-10-25 14:14:56');
INSERT INTO cs_test.article (id, title, content, sort, time) VALUES ('3', '标题三', '内容3', '1', '2020-10-25 14:13:20');
INSERT INTO cs_test.article (id, title, content, sort, time) VALUES ('4', '标题四', '内容4', '0', '2020-10-25 14:15:54');
INSERT INTO cs_test.article (id, title, content, sort, time) VALUES ('5', '标题五', '内容5', '0', '2020-10-25 14:15:56');`

求大神指教!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你的 time >= '2020-10-25 14:15:561` 已经把id = 3的数据给过滤掉了呀


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...