我有一个关于员工的表,其中有3列,如下面的代码:
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + DEPT
+ " TEXT NOT NULL," + NAME + " TEXT NOT NULL," + CITY + " TEXT NOT NULL);");
现在我只想向DEPT和CITY(e.i HCM City和Sales部门的员工)展示员工。如何查询才能获得它?
答案 0 :(得分:10)
@DienTrinh,你说得对,请注意AND
周围的空格。这对你有用。
Cursor cursor = db.query(TABLE_NAME,
new String [] {_ID, NAME, DEPT, CITY },
DEPT +"=?" +" AND " + CITY +"=?",
new String[] {"Sales", "HCM" },
null, null, null);
答案 1 :(得分:1)
SELECT * FROM Employees WHERE DEPT='Sales' AND City='HCM'