Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
name、amount in order amount desc を含む最小 1000 行を返すクエリを起動しています。その配列から特定の名前のインデックスが欲しいのですが、その方法がわかりません。
Rubyを使用しているので、適切にインデックスを返す arr.index(name)+1 メソッドを使用します。しかし、その特定の名前の数字のみを提供する MySQL クエリが必要です。
MySQL にはランキング機能はありません。あなたが得ることができる最も近いものは、変数を使用することです:
SELECT t.*, @rownum := @rownum + 1 AS rank FROM TABLE t, (SELECT @rownum := 0) r
これにより、rank という列が出力に追加されます。これは一意で、増分し、1 から始まります。