特定のテーブルを作成したいのですが、結果の一部の数値が2倍または3倍になります。これが状況です:
2つの表:支払いと費用
[Payments]: ID, studentID, Amount, DOP (a row in this table is a payment which a student pays it on DOP (date).
[Expenses]: ID, AmountPaid, TimeStamp (a row in this table is an expense bought such as papers or pens... on a specific date(timestamp)
私の質問は:
select
sum(purchases.amount) as 'Income From Students',
sum(Expenses.amountpaid) as 'Expenses',
sum(purchases.amount-expenses.amountpaid) as 'Net Profit',
datename(month,timestamp) as 'Month',
datepart(year,timestamp) as 'Year'
from expenses,purchases
group by datename(month,timestamp),datepart(year,timestamp)
クエリが示すように、私のテーブルには、毎月および毎年、支払い、費用、および純額の合計が表示されますprofit=payments - expenses
。
問題は、結果を取得するときに、sum(expenses.amountpaid)が常に2倍になることです。
だからどんなアイデアも...