SQL Progress Query - Non group by expression in select clause (7641_

Posted on 2013-11-18
Last Modified: 2013-11-18
Here is a simple query (see attached). When I add the SUM(Case when) clause it fails and get

"Non-group by expression in select clause"  I have tried several things but still can not get to work.
Question by:kelsanit
1 Comment
LVL 13

Accepted Solution

AielloJ earned 500 total points
ID: 39657135

When you use a SUM (or any other aggregate operator) all of the other items in the SELECT clause must use aggregate operators as well.  In your example you must add all the non-aggregate lines to a GOUP BY or similar statement.

 "INVOICE_TRL"."Invoice-Num", "INVOICE_TRL"."Invoice-Date", "INVOICE_TRL"."Prod-Pkg-Code", "INVOICE_TRL"."Quantity-Shipped", "INVOICE_TRL"."Cancelled", "INVOICE_TRL"."Type", "INVOICE_TRL"."Merchandise", "INVOICE_TRL"."Packaging-Code", "INVOICE_TRL"."Cust-ID", "INVOICE_TRL"."Sale-Measure", "CUST_SHIPTO"."territory", "INVOICE_TRL"."Product-Code",
Sum(Case When ("INVOICE_TRL"."Invoice-Date">={d '2012-09-30'} AND "INVOICE_TRL"."Invoice-Date"<={d '2012-12-29'}) then  "INVOICE_TRL"."Merchandise" else 0 end) as lastqtrsales
WHERE  "INVOICE_TRL"."Invoice-Date">={d '2012-04-01'}
GROUP BY  "INVOICE_TRL"."Invoice-Num", "INVOICE_TRL"."Invoice-Date", "INVOICE_TRL"."Prod-Pkg-Code", "INVOICE_TRL"."Quantity-Shipped", "INVOICE_TRL"."Cancelled", "INVOICE_TRL"."Type", "INVOICE_TRL"."Merchandise", "INVOICE_TRL"."Packaging-Code", "INVOICE_TRL"."Cust-ID", "INVOICE_TRL"."Sale-Measure", "CUST_SHIPTO"."territory", "INVOICE_TRL"."Product-Code",



Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 99
Access Date Query 28 44
SQL Server 2008 R2 - stored prodecure with execution plan make faster 24 115
SQL Statement to Update Email Domain 2 23
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now