|
Hi all, Can anyone help please I'm happy joining 2 table etc but how do I add in a 3rd-4th table to a query below? I needed was to get the sums and group by of the 3rd and 4th table... The 2 new tables are: ViewDis (X) - Field Sum (Distance) ViewACC (Y) - Fields Sum (Hours, Min, (Group by) Building and Date) Im not sure if the inner join is in the correct place and if I reference the fields correctly. Thanks for you help. Sql Newbie
(comments are locked)
|
|
Without having some data to play with, I'd say that your query is close. In the INNER JOIN's you specified a 'v1' & 'v2', however they don't correlate to any known alias in your query that I can see. My guess is that you would need to change the query to something like this: This would join the new tables to correlated query, however depending on your data and what the results need to look like, you might need to adjust this accordingly. Hope this helps! Hi There, Thanks for the reply. Great thanks so much for the pointer. I will give it a go asap.. :)
May 30 '12 at 03:35 PM
Unknownuser
(comments are locked)
|
|
Hi John, Yes thats correct There should be a "tick" you can click next to the beginning of John's answer. Please click it to mark the question as answered!
May 31 '12 at 12:59 PM
ThomasRushton ♦
(comments are locked)
|
|
Hi John, TheorWin is in both tables but for the specific task I need the sum of the X.theorwin. I used the physical name X.theorwin but now faced with -- Msg 8155, Level 16, State 2, Line 2 No column was specified for column 32 of 'A'. Can you please post the query as you currently have it?
May 31 '12 at 06:01 PM
JohnM
(comments are locked)
|


Hi there,
No Its didnt work, I got the go ahead from powers that be to post the script with a few changes so here it is.....Along with the error message!
The column 'ClubADW' doesn't exist in the dbo.ViewAccum1Day view or table, thus the error. Can you confirm that the column is present in the table or view?
If you were meaning to infer that column from the correlated subquery, you'll need to change the naming from 'X.ClubADW' to 'A.ClubAdw' in order to use that column.
Hope this helps!
Hi,
It exists in dbo.Viewaccum1day(TheorWin) but I just want to sum up all the values per playerid and location as ClubADW..
Hi,
I understand but It does exists in dbo.Viewaccum1day(TheorWin) but I just want to sum up all the values per playerid and location as ClubADW..
Sum (TheorWin) as ClubADW
Then as I mentioned previously, you'll need to adjust your query to either pull 'A.ClubADW' (the alias in the subquery) or 'X.TheorWin' which is the physical column name in the dbo.ViewAccum1Day table.
In either case, that should resolve the error that you are currently seeing.