id date group n1 n2 n3 n4 n5
18853 1945-01-05 BA 87 34 1 59 50
18854 1945-01-13 BA 6 66 1 16 48 <= the last 16, 7 rows to the end
18855 1945-01-20 BA 38 14 24 78 36
18856 1945-01-27 BA 49 30 87 15 65 <= the last 49, 5 rows to the end
18857 1945-02-03 BA 30 64 36 5 32
18858 1945-02-10 BA 15 36 37 86 31 <= the last 36, 3 rows to the end
18859 1945-02-17 BA 86 78 69 7 60 <= the last 86, 2 rows to the end
18860 1945-02-24 BA 83 7 72 88 19 <= the last 7, 1 row to the end
18861 1945-03-03 BA 47 20 77 73 30 <= the last 47, 0 rows to the end
我有上面的表格(它是按 id 排序的,但是我打算按日期排序)。有没有办法获取指定数字和mySql中最后一行之间的行数?请注意,某些数字会重复两次或更多次。该脚本应使用最低的行。这是 mySQL 应该输出的表:
Number|Rows count to the end
16|7
7|1
86|2
49|5
47|0
36|3
查询应搜索列 n1、n2、n3、n4、n5 并选择最接近末尾的值并将剩余的行计数到末尾。谢谢 ;)