我有这个表“CashMovementTbl”,“SalesTbl”& “ExpensesTbl”包括类似的数据:
我希望显示以下数据:
那么如何在SQL Server中进行查询以显示这样的数据。
答案 0 :(得分:1)
SELECT
c.CashDate,
ISNULL(s.BillNo,e.ExpnsType) As Details,
CASE WHEN c.SaleID IS NOT NULL THNE c.Amount ELSE 0 END AS [In],
CASE WHEN c.ExpenseID IS NOT NULL THNE c.Amount ELSE 0 END AS [Out]
FROM CashMovementTbl c
LEFT JOIN SalesTbl s
ON c.SaleID = s.SalesIS
LEFT JOIN ExpensensTbl e
ON c.ExpenseID = e.ExpnsID