Solved

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

Posted on 2013-11-18
1
1,107 Views
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.
query.docx
0
Comment
Question by:kelsanit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
AielloJ earned 500 total points
ID: 39657135
kelsanit,

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.

SELECT
 "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
FROM   ("CHEMPAX"."PUB"."CUST-SHIPTO" "CUST_SHIPTO" INNER JOIN "CHEMPAX"."PUB"."INVOICE-HDR" "INVOICE_HDR" ON ("CUST_SHIPTO"."Cust-ID"="INVOICE_HDR"."Cust-ID") AND ("CUST_SHIPTO"."Seq-Num"="INVOICE_HDR"."Shipto-Seq-Num")) INNER JOIN "CHEMPAX"."PUB"."INVOICE-TRL" "INVOICE_TRL" ON ("INVOICE_HDR"."Invoice-Num"="INVOICE_TRL"."Invoice-Num") AND ("INVOICE_HDR"."System-ID"="INVOICE_TRL"."System-ID")
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",

Regards,

AielloJ
0

Featured Post

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

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. …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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