嗨,我正在VS 2010,C#和SQLCe数据库中开发应用程序。
我正在从3个表分别生成收入,支出和交易的报告。
表结构如下:
收入:
费用:
交易:
为此,我写了查询
select t.tDate as [Date], t.tDescription as [Detail],e.eAmount as [Debit],
i.iAmount as [Credit], t.balance as [Balance]
from Transactions t
inner join Expence e on t.pid=e.pid
join Income i on t.pid=i.pid
where t.pid='11'
但是当我运行此查询时
我希望我的结果应该像下面的银行对帐单。
根据我的理解,查询是不正确的。
我们如何编写查询以获得这样的结果?
您必须使用left join
,而不是Join。因为left
返回from
表Expence e Income中存在表和case中的所有个案。
select t.tDate as [Date], t.tDescription as [Detail],e.eAmount as [Debit],
i.iAmount as [Credit], t.balance as [Balance]
from Transactions t
left join Expence e on t.pid=e.pid
left join Income i on t.pid=i.pid
where t.pid='11'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句