本文介绍了我该如何查询SQLite数据库有两个条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个3列像下面code职员表:
I have a table about employee with 3 columns like following code:
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + DEPT
+ " TEXT NOT NULL," + NAME + " TEXT NOT NULL," + CITY + " TEXT NOT NULL);");
现在我只是想表明在相同的DEPT和城市的员工都(E.I在胡志明市和销售部门的员工都)。我怎样才能查询得到它?
now I just want to show employees in the same both DEPT and CITY(e.i both employees in HCM City and Sales department). How can I query to get it?
推荐答案
@DienTrinh,你做得正确,注意周围的空间和
。这应该为你工作。
@DienTrinh, you had it right, note the spaces around AND
. That should work for you.
Cursor cursor = db.query(TABLE_NAME,
new String [] {_ID, NAME, DEPT, CITY },
DEPT +"=?" +" AND " + CITY +"=?",
new String[] {"Sales", "HCM" },
null, null, null);
这篇关于我该如何查询SQLite数据库有两个条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!