2011-08-22 69 views
0

我想在使用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 

感谢您的帮助!

+0

你正在寻找一种东西叫'ranking'可悲的是,我不知道SQLite的语法。 – Johan

回答

0

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

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

嗨,听起来不错。我尝试了以下方法:''创建临时表蝙蝠作为选择不同“+ col +”from“+ table +”;“+ \t \t \t \t \t”select _id,* from bat;'但我得到的例外是_id doesn' t存在...并且我尝试过:''创建临时表bat(_id整数主键自动增量,项目为select +“+ col +”from + + +)+ + + + + + + + + + + + + + + + + ;“但它也没有奏效。 – Droider