android - SQLite Left Outer Join 在 Android 中无法正常工作

标签 android sql sqlite join outer-join

我准备了一个左外连接查询,当我的 BLOB 表中存在与我的 INCIDENT 表中的记录匹配键的记录时,该查询应该返回非空数据。

基本上,数据和查询看起来像这样:

Table A
   Key

Table B
   Key
   Blob

and the query I'm running, should show all records from A, and the 'hasb' column should be 1 if there's a record in B with a matching key column, or 0 if there isn't. So the query should look like this:

SELECT A.*, ifnull(A.Key = B.Key, 0) as hasb FROM A
LEFT OUTER JOIN B ON A.Key = B.Key

好的,所以我的问题是,除了在 Android 设备上,这个查询似乎在我尝试使用它的任何地方都有效。

这是一个带有实际表和查询的 SQLFiddle。请注意,查询在那里有效。

http://sqlfiddle.com/#!7/89e7d/4

有人知道为什么这在 Android 上不起作用吗?我正在测试的设备是运行 Android 4.1.1 的三星 Galaxy S 3。

最佳答案

我认为您使用 ifnull 使事情过于复杂。

这是你的 fiddle 中的查询:

SELECT ifnull( a.userid = b.userid, 0 ) FROM incidentdata AS a
LEFT OUTER JOIN incidentblob AS b
ON ( a.userid = b.userid ) AND ( a.incidenttag = b.incidenttag );

这是我要写的查询:

SELECT a.userid, a.incidenttag, b._id, b._id is not null hasb
FROM incidentdata AS a
LEFT JOIN incidentblob AS b
ON a.userid = b.userid AND a.incidenttag = b.incidenttag

有用吗?如果不满意,请提供您正在使用的 SQLite 版本。无论如何,我很确定问题出在以下项目中:

  • 了解 null = null 不返回 TRUE 而是返回 null
  • null 值在执行 left join 后出现在 b.userida.incidentstag 中>

关于android - SQLite Left Outer Join 在 Android 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19122220/

相关文章:

sql - PostgreSQL - 按行组分页

c# - 带有 Sqlite 的 AdoJobStore

mysql - MySql 的 CommCare 导出工具出现 Unicode 错误

android - SQLite删除语法错误

android - Google Play 应用内商品价格不变

java - 为 ImageView 添加布局

android - 我的 Android 应用程序的某些用户遇到不满意的链接错误

android - appcompat-v7 :25. 3.0 : AppCompat does not support the current theme features: { windowActionBar: false, 窗口ActionBarOverlay : false, 。 }

sql - 使用 Azure ARM 模板导入数据库

sql - ORA-00937 : "not a single-group group function"