sqlite - 如何使用 whereArgs 在 SQLite Flutter 中选择 DISTINCT 条目?
问题描述
我想通过给出一些条件(例如返回 ID = x 的所有不同记录(其中 x 将由用户获取))从 SQLITE 颤振中的表中返回不同的记录。
我怎样才能做到这一点?
解决方案
使用SQFlite 包,您可以使用 aquery
或 arawQuery
来执行此操作,在这两种情况下,您都需要传递where arguments
as an array
,并且distinct operator
您可以按如下方式执行:
/// [GET] Get all the data by date using a query
getData(String date) async {
final db = await database;
final response = await db.query(
"TableExample",
distinct: true,
orderBy: 'id',
where: 'date = ?',
whereArgs: [date],
);
//...
}
/// [GET] Get all the data by date using a rawQuery
getDailyPollResponsesPerRangeDate(String date) async {
final db = await database;
final response = await db.rawQuery(
"SELECT DISTINCT TableExample.id, TableExample.date "
"FROM TableExample "
"WHERE TableExample.date == ? "
"ORDER BY TableExample.date DESC",
[date],
);
//...
}
推荐阅读
- c# - 扩展对象数组列表是否会生成一个新对象?
- javascript - 我想在 HTML 元素中显示函数的返回值,但返回值是 NAN
- c++ - 放置运算符新查找
- xamarin - Xamarin Forms 自定义控件绑定问题
- swift - 可选键的默认枚举值
- python - “用户警告:Matplotlib 当前使用的是 agg,这是一个非 GUI 后端,因此无法显示该图。” 在 Pycharm 上用 pyplot 绘制图形时
- r - 如何将反斜杠替换为 R 中整个 CSV 文件的正斜杠?
- json - React 认为我的“AbstractContract”是一个“对象”并且在我调用方法时不会呈现
- python - 为每个 Pandas 单元格设置相同的字典
- javascript - 在 Javascript 中从非关系数据库构建 JSON 树时遇到问题