Hi All, I need to execute below OQL to fetch some calculated data: select CAST(DATEPART(YEAR, EMP.DateFirstAccept) as STRING)+ ' - ' + CAST(DATEPART(WEEK, EMP.DateFirstAccept)as STRING) as col1, SUM(DATEDIFF(DAY,EMP.DateSubmitted, EMP.DateFirstInvite)): count(*) as col2, CAST(SUM(DATEDIFF(DAY, MST.DateSubmitted, MST.DateFirstAccept)): count(*) as DECIMAL ) as col3, CAST(SUM(DATEDIFF(DAY, MST.DateFirstEbmInvite, MST.DateFirstAccept)): count(*) as DECIMAL ) as col4 from Main.Employee as EMP where EMP.DateFirstAccept!= NULL and EMP.DateFirstInvite != NULL and EMP.DateSubmitted != NULL and EMP.DateSubmitted >= CAST('2019-06-03 00:00:00.000' as datetime) and EMP.DateSubmitted <= EMP.DateFirstInvite and EMP.DateSubmitted <= EMP.DateFirstAccept group by CAST(DATEPART(YEAR, EMP.DateFirstAccept) as STRING)+ ' - ' + CAST(DATEPART(WEEK, EMP.DateFirstAccept)as STRING) However, it gives error that : Column 'MST.DateFirstAccept' cannot both be aggregated and appear in the GROUP BY clause. Please suggest if you know a way around this. Thanks.
asked
Monali Patil
1 answers
0
Hi, it was the right assumption to setup the group by, only without the cast function.
group by DATEPART(YEAR, EMP.DateFirstAccept), DATEPART(WEEK, EMP.DateFirstAccept)