I use Microsoft SQL Svr Mgmt Studio 2008. I do not have access to create a temporary table (the company limits the ability to create or modify tables), or I would use this to solve this problem.
I have successfully used the join query to combine the results of the three selected queries. Now I am trying to summarize the results of the union.
When I execute the request below, I get:
Incorrect syntax near the keyword 'GROUP'
And then when I delete the group, I get:
Incorrect syntax near ')'
Here is my request:
Select Period, PCC, SUM(BasicHits), SUM(FareHits), SUM(SearchHits) From ( SELECT AAAPeriod AS Period, AAAFromPCC AS PCC, - SUM(AAABasic) AS BasicHits, - SUM(AAAFare) AS FareHits, - SUM(AAASearch) AS SearchHits FROM HitsAaa HAVING (AAAPeriod = N'2010-10') UNION ALL SELECT AAAPeriod, AAAtoPCC, SUM(AAABasic), SUM(AAAFare), SUM(AAASearch) FROM HitsAaa HAVING (AAAPeriod = N'2010-10') UNION ALL SELECT AgtPeriod, AgtPcc, SUM(AgtBasic), SUM(AgtFare), SUM(AgtSearch) FROM HitsAgent HAVING (AgtPeriod = N'2010-10') )GROUP BY Period, PCC
I could not find a solution to this question on any of the previous questions.
source share