Home > Mobile >  SQL Max from Subquery, Msg 102, Incorrect syntax near ')'
SQL Max from Subquery, Msg 102, Incorrect syntax near ')'

Time:02-11

I'm trying to get only the Max-Results of the sums per day. I'm trying this with Select Max(Anzahl) from (Subquery)

The Subquery itself works, but when I put it into the brackets, I get the following error message:

Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.

See below for the whole query.

Many thanks for any hints! Cheers Lukas

select Max(Anzahl) from
(
select CONVERT(VARCHAR(10), log1.timestamp, 104) as Date, log1.ID, count(*) Anzahl
from log1
inner join base on log1.ID = base.ID
where abc like '%test%' and log1.xyz = 3
GROUP BY CONVERT(VARCHAR(10), log1.timestamp, 104), log1.ID
)

CodePudding user response:

In SQL every derived table requires an alias so it can be uniquely identified, so

select Max(Anzahl) from
(
select CONVERT(VARCHAR(10), log1.timestamp, 104) as Date, log1.ID, count(*) Anzahl
from log1
inner join base on log1.ID = base.ID
where abc like '%test%' and log1.xyz = 3
GROUP BY CONVERT(VARCHAR(10), log1.timestamp, 104), log1.ID
) as AliasName
  • Related