How to show rows in packs of three in MySQL
问题 I have a table like this: ID Type Timestamp 1 A 101 2 A 102 3 B 103 4 B 104 5 A 105 6 B 106 7 A 107 8 A 108 9 B 109 10 A 110 11 B 111 12 B 112 ... I want to show a result sorted by Type and Timestamp where every 3 rows the Type changes like this: ID Type Timestamp 1 A 101 2 A 102 5 A 105 3 B 103 4 B 104 6 B 106 7 A 107 8 A 108 10 A 110 9 B 109 11 B 111 12 B 112 ... 回答1: If you are running MySQL 8.0, consider: SELECT * FROM mytable ORDER BY FLOOR((ROW_NUMBER() OVER(PARTITION BY type ORDER BY