Can't get my head round this

geoffcodd

Registered User.
Local time
Today, 14:07
Joined
Aug 25, 2002
Messages
87
I've also attached this as a word doc as it is easier to follow

I have the following Tables

Table 1

Utility_Type RunningSum Month
Oil £3,342.43 Sep
Oil -£42,441.32 Nov

Table 2

Utility_Type RunningSum Month
Oil £3,505.62 Oct
Oil £10,416.39 Nov
Oil £25,048.29 Dec
Oil £39,091.83 Jan
Oil £44,734.82 Feb
Oil £62,531.21 Mar
Oil £71,656.36 Apr
Oil £78,703.18 Jun

Table 3

Month_No Month_Name
1 Sep
2 Oct
3 Nov
4 Dec
5 Jan
6 Feb
7 Mar
8 Apr
9 May
10 Jun
11 Jul
12 Aug

From these tables I have created the following query

SELECT Reading_Dates.Month_No, Reading_Dates.Month_Name, CBUDPresGRS.RunningSum, CBUDPrevGRS.RunningSum
FROM (Reading_Dates LEFT JOIN CBUDPresGRS ON Reading_Dates.Month_Name = CBUDPresGRS.Month) LEFT JOIN CBUDPrevGRS ON Reading_Dates.Month_Name = CBUDPrevGRS.Month
GROUP BY Reading_Dates.Month_No, Reading_Dates.Month_Name, CBUDPresGRS.RunningSum, CBUDPrevGRS.RunningSum
ORDER BY Reading_Dates.Month_No;

Which gives the following result

Month_No Month_Name RunningSum1 RunningSum2
1 Sep £3,342.43
2 Oct £3,505.62
3 Nov -£42,441.32 £10,416.39
4 Dec £25,048.29
5 Jan £39,091.83
6 Feb £44,734.82
7 Mar £62,531.21
8 Apr £71,656.36
9 May
10 Jun £78,703.18
11 Jul
12 Aug

What I need it to show is

Month_No Month_Name RunningSum1 RunningSum2
1 Sep £3,342.43 £0
2 Oct £3,342.43 £3,505.62
3 Nov -£42,441.32 £10,416.39
4 Dec £25,048.29
5 Jan £39,091.83
6 Feb £44,734.82
7 Mar £62,531.21
8 Apr £71,656.36
9 May £71,656.36
10 Jun £78,703.18
11 Jul £78,703.18
12 Aug £78,703.18

Thanks in advance
Geoff
 

Attachments

Users who are viewing this thread

Back
Top Bottom