mysql - 论坛帖子排序问题
天蓬老师
天蓬老师 2017-04-17 16:07:11
0
2
765
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
洪涛

It is recommended to use a temporary table to sort again and again. Each time the sorting results are placed in the temporary table to see if they are correct, and then the next sorting is performed.

Finally, optimize all sorted SQL statements into one.

巴扎黑

PS: SQL should be posted in code form as much as possible for the respondent to modify

You can left join the main table to a table with only the first three records, similar to:

SELECT a.*,
       b.count AS new_count
FROM test a
LEFT JOIN
  ( SELECT * FROM test ORDER BY count DESC LIMIT 0, 3 ) b
ON a.id=b.id
ORDER BY new_count DESC,date DESC;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template