Hi
In below query i want to group by code,name. But when i group then it gives error DueDate is not grouped by.
SELECT T1."CardCode", T1."CardName",
CASE
when (DAYS_BETWEEN(T0."DueDate", now()))+1 < 31
then
case
when T0."SYSCred" <> 0 then -T0."SYSCred"
else T0."SYSDeb"
end
end "0-30 days",
FROM JDT1 T0 inner join OCRD T1 on T1."CardCode" = T0."ShortName"
INNER JOIN OJDT T2 ON T2."TransId"=T0."TransId"
WHERE T1."U_MSME" = 'Y'
AND "T1"."CardType" = 'S'
ORDER BY T1."CardCode", T0."TaxDate"
Thanks
Jayraj ChhayaPosted Nov 7, 2024, 5:56 AM
Hello Ramco Ramco,
The error you are experiencing arises because SQL requires that all selected columns in a
GROUP BYquery must either be included in theGROUP BYclause or be aggregated. In your case, theDueDateis not included in theGROUP BY, which leads to the error.To resolve this, you can either include
DueDatein yourGROUP BYclause or apply an aggregate function to it. Here’s a modified version of your query that groups byCardCodeandCardName, while also using an aggregate function for theDueDate:I used
MAX(T0."DueDate")to ensure that theDueDateis aggregated, thus resolving the error while maintaining the intended functionality of your query.Jignesh KumarPosted Nov 7, 2024, 5:07 AM
Hello Ramco,
You can use below query to do group by, You have not applied group by in your query.