我在下面有这个代码,其中所有数据都包含' grpnumber'。我的问题是:如何获得2 where子句?我想获得具有组号和卡路里的记录?
String[] projection = {
FoodReaderContract.FoodGroupEntry._ID,
FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_NUMBER,
FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_FOODNAME,
FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_TIMEOFDAY,
FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_CALORIE
};
// Filter results WHERE "title" = 'My Title'
String selection = FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_NUMBER
+ " = ?";
String[] selectionArgs = {grpnumber};
//String selection = FeedReaderContract.FooEntry._ID + " = ?";_
//Int[] selectionArgs = {2};
// How you want the results sorted in the resulting Cursor
String sortOrder =
FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_NUMBER + " DESC";
Cursor cursor = db.query(
FoodReaderContract.FoodGroupEntry.GROUP_TABLE_NAME, // The table to query
projection, // The columns to return
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
答案 0 :(得分:1)
您可以使用 AND 关键字。
String selection = FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_NUMBER + " = ? "
+ " AND " + FoodReaderContract.FoodGroupEntry.COLUMN_GROUP_CALORIE + " = ?";
String[] selectionArgs = {String.valueOf(grpnumber), String.valueOf(calorie)};