我有这张桌子:
id | CUPNAME | FRENCHNAME
1 | 2 | null
2 | null | 4
我想从CUPNAME和FRENCHNAME中提取数据,这些数据不为空。
该表可以填充从1到10的数字。在本示例中,应该能够CUPNAME = 2,FRENCHNAME = 4。
有这样的查询:
SELECT sum(ifnull(french_press_bd.CUPNAME,0)) as a , sum(ifnull(french_press_bd.FRENCHNAME,0)) as b FROM my_table WHERE id in (1,2)
我尝试写,所以它不起作用:
String sqr = "id in (1,2)";
Cursor cursor = sqdb.query(french_press_bd.TABLE_NAME, new String[] {
"sum(ifnull(french_press_bd.CUPNAME,0)) as a , sum(ifnull(french_press_bd.FRENCHNAME,0)) as b"
},sqr, null,null,null,null );
最佳答案
我认为您可以使用rawQuery。如:
String your_query= "SELECT sum(ifnull(french_press_bd.CUPNAME,0)) as a , sum(ifnull(french_press_bd.FRENCHNAME,0)) as b FROM my_table WHERE id in (1,2)";
Cursor result = sqdb.rawQuery(your_query, null);
但是请确保
SQLiteDatabase
不是NULL
。你必须先打电话sqdb = dbhelper.getReadableDatabase(); // or getWritableDatabase()
关于android - SQLiteDatabase在查询中需要帮助...请,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19713458/