2011-08-22 68 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