[英]How to use Multiple values from Multiple column in sqlite using query?
我有五列,我想從五列搜索數據,但列值可以超過5,它不固定。
例
列名
直呼其名,最后名稱,主題,因此,品位。
我想使用sqlite搜索多個值。(名字可以是a,b,c,d)
怎么實現這個?
任何幫助,將不勝感激。
在SQLite中使用IN
關鍵字將允許您使用一組多個值執行搜索。 例如:
SELECT * FROM table WHERE first-name IN ('a', 'b', 'c', 'd');
現在你可以做的是使用任何循環構建一個輸入(可搜索的單詞)參數,並將其替換為IN
括號。
例如:
String names = "'a', 'b', 'c', 'd'"; /* build it through loop */
Cursor c = db.rawQuery("SELECT * FROM table WHERE first-name IN (?)",
new String[]{names});
有多列:
String names = "'a', 'b', 'c', 'd'"; /* build it through loop */
Cursor c = db.rawQuery("SELECT * FROM table WHERE first-name IN (?)
OR last-name IN (?) OR subject IN (?) OR result IN (?) OR grade IN (?)",
new String[]{names, names, names, names, names});
String[] names = new String[3];
String QueryArgs ="";
for(int index=0;index < 3;index++)
{
QueryArgs = QueryArgs.concat(",?");
names [index] = "xyz";
}
QueryArgs = QueryArgs.substring(1);
Cursor dataset = db.rawquery("select * from table where name in(" +QueryArgs+ ")",names);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.