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の最後の行の間の行数を取得する方法はありますか? 一部の数字は 2 回以上繰り返されることに注意してください。スクリプトは最下位の行を使用する必要があります。mySQL が出力するテーブルは次のとおりです。
Number|Rows count to the end
16|7
7|1
86|2
49|5
47|0
36|3
クエリは列 n1、n2、n3、n4、n5 を検索し、最後に最も近い値を選択し、残りの行を最後まで数えます。ありがとう ;)