Hi Guys,
I want to create a specific table but some numeric values are doubled or tripled in the result.
here is the situation:
2 tables: Payments and Expenses
[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)
my query is:
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)
as the query tells: my table should display for each month and each year the sum of payments, expenses and net profit=payments - expenses.
the problem is, when getting the result, sum(expenses.amountpaid) is always doubled.
so any ideas...