Sqlite Join(或其某些变体)
给定这样的结果集:
Col1 Col2
============
BAML 491
BARC 362
BDPT 1
BNP 9
(select Col1, count(some_col) as Col2 from Table where another_col='SomeCondition" group by Col1)
和另一个这样的结果集:
Col3 Col2
============
BAML 494
BARC 366
BDPT 1
BNP 10
CALY 3
(select Col3, count(some_col) as Col2 from Table where another_col='SomeOTHERCondition " group by Col3)
如何“合并”这两个查询以形成:
BAML 491 494
BARC 362 366
BDPT 1 1
BNP 9 10
CALY 3
请注意,前两个查询在同一个表上运行。我可以在这里看到 Join 帮助的一些变体(还没有太多地使用 sql)。我只是不知道如何将这两个查询放入单个查询中以获取合并的 reusltset。
Given a resultset like this:
Col1 Col2
============
BAML 491
BARC 362
BDPT 1
BNP 9
(select Col1, count(some_col) as Col2 from Table where another_col='SomeCondition" group by Col1)
and another like this:
Col3 Col2
============
BAML 494
BARC 366
BDPT 1
BNP 10
CALY 3
(select Col3, count(some_col) as Col2 from Table where another_col='SomeOTHERCondition" group by Col3)
How do I "merge" these two queries to form:
BAML 491 494
BARC 362 366
BDPT 1 1
BNP 9 10
CALY 3
Please note that the first two queries operate on the same table. I can see some variant of Join helping here (haven't worked with sql all that much). I just can't figure out how to put those two queries into a single query to get the merged reusltset.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
我不确定 SQLite 是否支持这一点。
根据评论,上面的方法确实有效,但你确实想要一个完整的外部连接,而 SQLite 不喜欢这样。不过,您可以尝试用两个 LEFT OUTER JOIN 和一个 UNION 来伪造它:
Try this:
I'm not sure if SQLite supports that though.
Based on the comments the above does work but you really want a FULL OUTER JOIN and SQLite doesn't like that. You could try faking it with two LEFT OUTER JOINs and a UNION though: