SQLite android名称计数
我有一张桌子的历史记录 历史记录表有3列SQLite android名称计数,android,sqlite,Android,Sqlite,我有一张桌子的历史记录 历史记录表有3列 ID | timestamp | imagename 我需要计算所有的图像,其中的名称就像我从我的应用程序转发的名称 范例 1 | 12.12.2019 | 88801 2 | 11.11.2019 | 88802 3 | 13.1.2019 | 88802 4 | 1.2.2015 | 88801 5 | 7.8.2019 | 88801 我需要这样的结果 Image name| number of images 8
ID | timestamp | imagename
我需要计算所有的图像,其中的名称就像我从我的应用程序转发的名称
范例
1 | 12.12.2019 | 88801
2 | 11.11.2019 | 88802
3 | 13.1.2019 | 88802
4 | 1.2.2015 | 88801
5 | 7.8.2019 | 88801
我需要这样的结果
Image name| number of images
8801 | 3
8802 | 2
我需要通过转发变量imageName来计算它
这就是我现在拥有的
public List<HistoryLog> getAllHistoryLogsForListView(String imageName) {
List<HistoryLog> historyLogList = new ArrayList<>();
// Select All Query ORDER BY Timestamp | SORT ASC | LIMIT 150 rows
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIMESTAMP + " ASC " + " LIMIT 150";
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
HistoryLog historyLog = new HistoryLog();
historyLog.setId(Integer.parseInt(cursor.getString(0)));
historyLog.setTimeStamp(cursor.getString(1));
historyLog.setImageName(cursor.getString(2));
// Adding history logs to list
historyLogList.add(historyLog);
} while (cursor.moveToNext());
}
db.endTransaction();
// return history logs list
return historyLogList;
}
公共列表getAllHistoryLogsForListView(字符串imageName){
List historyLogList=新建ArrayList();
//按时间戳选择所有查询顺序|排序ASC |限制150行
String selectQuery=“SELECT*FROM”+表\历史+”按“+键\时间戳+”ASC“+”限制150”排序;
SQLiteDatabase db=this.getWritableDatabase();
db.beginTransaction();
Cursor Cursor=db.rawQuery(selectQuery,null);
//循环遍历所有行并添加到列表
if(cursor.moveToFirst()){
做{
HistoryLog HistoryLog=新的HistoryLog();
setId(Integer.parseInt(cursor.getString(0));
setTimeStamp(cursor.getString(1));
setImageName(cursor.getString(2));
//将历史记录日志添加到列表
添加(historyLog);
}while(cursor.moveToNext());
}
db.endTransaction();
//返回历史记录日志列表
返回historyLogList;
}
按图像名称从历史记录TBL组中选择图像名称、计数(图像名称)使用:
然后,您可以从游标获取每个图像的计数:
final Map<Integer, Integer> imageCount = new HashMap<>();
// where key is imagename (int) and value is count (int)
if (c.moveToFirst()) {
do {
imageCount.put(
c.getInt(0),
c.getInt(1)
);
} while (c.moveToNext());
}
final Map imageCount=new HashMap();
//其中键是imagename(int),值是count(int)
if(c.moveToFirst()){
做{
imageCount.put(
c、 getInt(0),
c、 getInt(1)
);
}而(c.moveToNext());
}
不清楚您到底想要什么?我想知道有多少图像具有相同的名称,我需要对其进行计数
final Map<Integer, Integer> imageCount = new HashMap<>();
// where key is imagename (int) and value is count (int)
if (c.moveToFirst()) {
do {
imageCount.put(
c.getInt(0),
c.getInt(1)
);
} while (c.moveToNext());
}