こんにちは私はVS2010、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
結合を使用するのではなく、を使用する必要があります。left
テーブル内のすべてのケースを返し、ケースはfrom
テーブルExpence eIncomeに存在するためです。
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]
コメントを追加