john33john33
Registered User.
- Local time
- Tomorrow, 05:22
- Joined
- Jul 23, 2015
- Messages
- 18
Table RecycleRecord
ItemName, RecordDate, Amount
Paper, 1/7/2013, 100
Table RecycleItem
ItemName, UnitInKg
Paper 1
Table PaperType
PaperType, KgPerUnit
A4 Paper, 2.5
Table PaperUsage
PaperType, RecordDate, Amount
A4 Paper, 2/7/2013, 100
I want results like PaperUsage.Amount*PaperType.KgPerUnit - RecycleItem.UnitInKg*RecycleRecord.Amount
If in the same month, then group it to see the net paper usage.
Trial:
As RecycleRecord.RecordDate is not necessary equal to PaperUsage.RecordDate, I have to use Month(RecycleRecord.RecordDate) = Month(PaperUsage.RecordDate).
However, it shows lack of operand.
Thanks for all feedback.
ItemName, RecordDate, Amount
Paper, 1/7/2013, 100
Table RecycleItem
ItemName, UnitInKg
Paper 1
Table PaperType
PaperType, KgPerUnit
A4 Paper, 2.5
Table PaperUsage
PaperType, RecordDate, Amount
A4 Paper, 2/7/2013, 100
I want results like PaperUsage.Amount*PaperType.KgPerUnit - RecycleItem.UnitInKg*RecycleRecord.Amount
If in the same month, then group it to see the net paper usage.
Trial:
Code:
SELECT Sum(PaperUsage.Amount*PaperType.KgPerUnit-RecycleItem.UnitInKg*RecycleRecord.RecordDate) AS Kg
FROM PaperType INNER JOIN PaperUsage ON PaperType.PaperType = PaperUsage.PaperType
INNER JOIN RecycleRecord ON Month(RecycleRecord.RecordDate) = Month(PaperUsage.RecordDate)
INNER JOIN RecycleItem ON RecycleRecord.ItemName = RecycleItem.ItemName
GROUP BY Month(PaperUsage.RecordDate), PaperUsage.RecordDate
ORDER BY PaperUsage.RecordDate;
As RecycleRecord.RecordDate is not necessary equal to PaperUsage.RecordDate, I have to use Month(RecycleRecord.RecordDate) = Month(PaperUsage.RecordDate).
However, it shows lack of operand.
Thanks for all feedback.