Solved

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

Posted on 2013-11-18
1
889 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

18 Experts available now in Live!

Get 1:1 Help Now