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.
我正在触发一个查询,该查询返回至少 1000 行,其中包含名称、订单金额 desc 中的金额。我想要该数组中某个名称的索引,我不知道该怎么做?
当我使用 Ruby 时,我使用 arr.index(name)+1 正确返回索引的方法。但我想要一些 MySQL 查询,它只给我那个特定名称的数字。
MySQL 中没有排名功能。您可以获得的最接近的是使用变量:
SELECT t.*, @rownum := @rownum + 1 AS rank FROM TABLE t, (SELECT @rownum := 0) r
这将在您的输出中添加一个名为 rank 的列,该列将是唯一的、递增的,并且从 1 开始。