gpt4 book ai didi

android - 用于 INNER JOIN 的 sqliteDatabase.query()

转载 作者:行者123 更新时间:2023-11-29 14:31:04 25 4
gpt4 key购买 nike

我想从 Android SQLite 数据库中执行如下查询:

select place.permit_name, local.local_distance
from tblLocal local
inner join tblPlaces place
on place._id = local._id
order by local.local_distance asc

我正在尝试使用 query(),而不是 rawQuery()。我不知道如何指定 INNER JOIN/ON。我该怎么做?

final String table = PlacesDataContract.PlacesDataEntry.TABLE_NAME;
final String[] columns = { PlacesDataContract.PlacesDataEntry.COLUMN_NAME_PERMIT_NAME. , LocalDataContract.LocalDataEntry.COLUMN_NAME_LOCAL_DISTANCE};
final String orderBy = LocalDataContract.LocalDataEntry.COLUMN_NAME_LOCAL_DISTANCE + " ASC";

Cursor cursor = sqLiteDatabase.query(table, // table
columns, // columns
null, // selection
null, // selectionArgs
null, // groupBy
null, // having
orderBy, // orderBy
null); // limit

最佳答案

您可以将联接放在 table 变量中。

String table = "tblLocal local " +
"inner join tblPlaces place " +
"on place._id = local._id";

有关示例,请参阅 Google 的 IOSched 应用程序。看看 provider包和 SelectionBuilder类。

SQLiteQueryBuilder 用于构建查询字符串,它所做的只是将表变量连接到查询的其余部分。参见 https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/database/sqlite/SQLiteQueryBuilder.java#201

关于android - 用于 INNER JOIN 的 sqliteDatabase.query(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31567564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com