【问题标题】:Continuous numbering of a the retrieved data in an extra column在额外的列中对检索到的数据进行连续编号
【发布时间】:2011-08-22 22:34:53
【问题描述】:

当我使用 SELECT DISTINCT 查询时,我想获得一个编号游标。

表:

| _id | Name  |
| 1   | Jones | 
| 2   | Smith | 
| 3   | Jones | 
| 4   | Taylor| 
| 5   | Brown | 
| 6   | Brown | 
| 7   | Brown |  

我想得到这样的光标:

| _id | Name  |
| 1   | Jones | 
| 2   | Smith | 
| 3   | Taylor| 
| 4   | Brown |

我尝试了很多,但没有成功。 有时没有唯一值,有时我在选择项目时收到以下错误:

08-22 22:18:15.413: ERROR/AndroidRuntime(1053): java.lang.IllegalStateException: this should only be called when the cursor is valid

感谢您的帮助!

【问题讨论】:

  • 您正在寻找一个名为 ranking 的东西,遗憾的是我不知道 SQLite 语法。

标签: android sql sqlite unique distinct


【解决方案1】:

我认为最简单的方法是使用临时表:

'create temporary table bat as select distinct name from yourtable; 
 select rowid, * from bat ; ' 

【讨论】:

  • 嗨,听起来不错。我尝试了以下方法:"create temporary table bat as select distinct "+col +" from "+table+";"+ "select _id, * from bat ; 但我得到了 _id 不存在的异常......我尝试了:"create temporary table bat (_id integer primary key autoincrement, item as select distinct "+col+" from "+table+");"+ "select _id,"+col+" from bat;" 但它也没有用。
猜你喜欢
  • 2017-01-17
  • 2021-12-03
  • 1970-01-01
  • 2019-12-25
  • 2016-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-29
相关资源
最近更新 更多