Really new to SQL. Please help

hawkinsr86

New member
Local time
Today, 10:51
Joined
Apr 23, 2013
Messages
2
Can someone please tell me whats wrong with the following code

SELECT Month &"-"& Year AS Concat FROM New_Raw_Data
GROUP BY Concat

I keep getting the error "you treid to execute a query that does not include the speficied expression..........

Thanks!
 
G'd Afternoon Hawkins,
You don need the Group by unless you need to count/sum/etc.

This is enough
SELECT Month &"-"& Year AS Concat FROM New_Raw_Data
 
Thanks Estuardo. I do want to sum the expense amount, i.e. below.

This runs fine and gives me the result I want

SELECT Month&"-"&Year AS Concat, SUM ([Expense Amount]) AS Total FROM New_Raw_Data
GROUP BY Month&"-"&Year

Then when I change it to this it doesnt

SELECT Month&"-"&Year AS Concat, SUM ([Expense Amount]) AS Total FROM New_Raw_Data
GROUP BY Concat

The only thing thats different is the bit highligted yellow.

Thanks in advance
 
You can not use an alias in a Group by

Always include all info, not just a bit else people will answer the wrong question as per Estuardo.

Brian
 
Hawkins,
Brian is right you can't use an alias in a group by. That's why the Error.
Thanks Brian for the point :)
 

Users who are viewing this thread

Back
Top Bottom