2016-08-21 46 views
-1

最後的行和列的值,我想最後的值例子獲取sqlLite

ID NAME SURNAME 
1 Mark X 
2 Alex Z 

我想在那裏姓等於Z中的數值,或插入y的驗證碼

的最後一個值

DB類

public Cursor getData(){ 

    SQLiteDatabase db = this.getWritableDatabase(); 
    //String selectQuery= "SELECT * FROM "+TABLE_NAME+" ORDER BY column DESC LIMIT 1;"; 
    Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_NAME,null); 

    //Cursor cursor = db.rawQuery(selectQuery,null); 




    return cursor; 



} 

主要活動

void getDatas(){ 
    Cursor c = helper.getData(); 
    if (c.getCount()==0){ 

     return; 

    } 

    StringBuffer buffer = new StringBuffer(); 
    while (c.moveToNext()){ 
      buffer.append(c.getString(2)); 

    } 

    TEXT=buffer.toString(); 

} 

隨着那我收到例如= XZ而不是隻有ž

回答

1

我想你想是這樣的:

select t.* 
from table t 
order by (case when surname = 'Z' then 1 else 2 end), 
     id desc 
limit 1;