我也总4条记录ecare表,其中2 records
状态发送= 1,和其他2条状态sent = 0
SQLite的获取只有最后一个记录不是所有的记录
RECORDS
1st Record : Track 1 [sent = 1]
2nd Record : Track 2 [sent = 1]
3rd Record : Track 3 [sent = 0]
4th Record : Track 4 [sent = 0]
但只得到最后记录(即 - 轨道4)不全2记录那些状态发送= 0
这里是SQLite的查询,其中我使用来从数据库
public synchronized List<String> getECareData() {
String sql = "SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0' GROUP BY e.h_id";
List<String> records = new ArrayList<String>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
records.add(cursor.getString(0));
}
return records;
}
数据进行更新
public synchronized List<String> getECareData() {
String sql = "SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0' GROUP BY e.h_id";
List<String> records = new ArrayList<String>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
records.add(cursor.getString(0));
} while (cursor.moveToNext());
}
Log.d("records:", records.toString());
return records;
}
日志说:
D/records:: [Getting only LAST record here] the 4th one
我想,有一个与查询东西wrong
,因为我在只获得最后一个记录光标
更新的记录
1st Record : Track 1 [sent = 1]
2nd Record : Track 2 [sent = 1]
3rd Record : Track 3 [sent = 0]
4th Record : Track 4 [sent = 0]
5th Record : Track 5 [sent = 0]
但只得到最后记录(即 - 轨道5)不所有三个记录那些状态发送= 0
日志说:
D/records:: [Getting only LAST record here] the 5th one
更新的查询 - 从查询中移除GROUP BY
现在得到每一条记录,即使是那些属于的发送= 1而我只是想获取属于发送= 0的数据仅
String sql = "SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0' ";
在while循环之前执行cursor.moveToFirst()。 –
请注意,'LEFT JOIN p ... WHERE p ...'与'INNER JOIN p'相同' – Strawberry
@ayeshdon请参阅UPDATED部分,但仍只获得最后一条记录,不是记录 – Oreo