1

I have the following query and it gives me an error :"Incorrect syntax near the keyword 'GROUP'." <-shows me the second GROUP BY statement...Can you tell me why?

SELECTventId
,TargetUser
,TargetDomain
,String05
,Amount
,max(Amount) maximum 
FROM
   (SELECT    EventId
              , TargetUser
              , TargetDomain
             , String05 
FROM  AdtServer.dvAll 
GROUP BY EventId, TargetUser, TargetDomain, String05)

GROUP BY EventId,TargetUser,TargetDomain,String05,Amount //ERROR SHOWS HERE

ORDER BY maximum,TargetUser

If I create view for inner query it works fine(But I don't want to create a view because if my query is long-running query it gives me time-out).

2 Answers 2

1

You need to give an alias to your table:

SELECTventId 
,TargetUser 
,TargetDomain 
,String05 
,Amount 
,max(Amount) maximum  
FROM 
   (SELECT    EventId 
              , TargetUser 
              , TargetDomain 
             , String05  
    FROM  AdtServer.dvAll  
    GROUP BY EventId, TargetUser, TargetDomain, String05
    ) x
GROUP BY EventId,TargetUser,TargetDomain,String05,Amount 
ORDER BY maximum,TargetUser
Sign up to request clarification or add additional context in comments.

1 Comment

You are right I found the answer but because of you are absolutely right I will give you accept..Thank you very much..:)
1

I found the answeeeeeeeer

I should have written as tempTB I mean my query should look like this:

SELECTventId
,TargetUser
,TargetDomain
,String05
,Amount
,max(Amount) maximum 
FROM
   (SELECT    EventId
              , TargetUser
              , TargetDomain
             , String05 
FROM  AdtServer.dvAll 
GROUP BY EventId, TargetUser, TargetDomain, String05) as tempTB
GROUP BY EventId,TargetUser,TargetDomain,String05,Amount 

ORDER BY maximum,TargetUser

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.