我想在一组数据中添加一个“计数器”列,以便我得到以下内容:
输入
class MainActivity : AppCompatActivity() {
inner class Anon : Observer<PagedList<ApplicationUsers>> {
override fun onChanged(pagedList: PagedList<ApplicationUsers>?) {
Toast.makeText(this@MainActivity, "hello", Toast.LENGTH_SHORT).show()
}
}
}
输出
COLUMN_NAME
<value1>
<value2>
...
<valuen>
我假设我的原始数据已按照我希望的那样排序。
谢谢!
答案 0 :(得分:0)
MySQL的:
SELECT t.COLUMN_NAME,
@rownum := @rownum + 1 AS COUNTER_COLUMN
FROM YourTableName t,
(SELECT @rownum := 0) r
答案 1 :(得分:0)
得到答案:
SELECT
t.COLUMN_NAME,
ROW_NUMBER() over(order by COLUMN_NAME) as COUNTER_COLUMN
from MY_TABLE t
;