![](/img/trans.png)
[英]How can I join two tables but get results from table one where theres no entry in table two?
[英]How can I join two tables and get a count of the number of times the joins match if there might not be a corresponding entry in one table?
在 SQLite 我有两个表:
public class DeckSource {
[PrimaryKey, NotNull]
public string DeckGuid { get; set; }
public string Type { get; set; }
public string Name { get; set; }
}
和
public class Deck {
[PrimaryKey, NotNull]
public long IdEs { get; set; }
public string DeckGuid { get; set; }
public string Type { get; set; }
public string Name { get; set; }
}
我的应用程序有一个添加按钮,按下该按钮时会从 DeckSource 中的一行获取数据并填充 Deck。 所以对于每个 DeckSource 可以有多个卡组。 我想从 DeckSource 获得一份报告,显示每个 Deck 被添加到 Deck 的次数。
如果 DeckSource 表如下所示:
DeckGuid Name
abc abcrow
def deform
ghi ghirow
和甲板看起来像这样:
IdEs DeckGuid Name
1 abc abcrow
2 abc abcrow
3 abc abcrow
4 chi ghirow
如何创建显示以下内容的报告:
DeckGuid Name Qty
abc abcrow 3
def defrow 0
ghi ghirow 1
你试过这个吗?
select decksource.deckguid,decksource.name,count(*)
from decksource
left join deck
on decksource.deckguid = deck.deckguid
group by decksource.deckguid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.