SQL Query - question about subqueries

Posted by dpackerSIG on 28-Aug-2018 02:31

Is it possible to create a subquery using Progress SQL to show summarized child-level data in the same row as the parent?

For example: Header table is SalesOrder, Detail table is SalesLine:

SELECT SalesOrder.OrderNumber, SalesOrder.CustomerNumber, [Some SQL code to get the total of Qty * Unit Price for all related SalesLine records] FROM PUB.SalesOrder

Thanks for any advice!

Posted by Etienne Begin on 28-Aug-2018 08:46

You can only use a column name or expression.  An expression can be an aggregate (min/max) or scalar function such as year/replace/trim.  Note that also means you can use hardcoded string values like

select "stringname" as 'column1'

No sub-queries.

You should work to find a way to avoid using a subquery.  It seems possible from your example.

Etienne

All Replies

Posted by David Abdala on 28-Aug-2018 05:52

I may not have understood the question, but you don't need subquerys for that:

SELECT SalesOrder.OrderNumber, SUM(SalesLine.Qty * SalesLine.Price) AS GrandTotal FROM SalesOrder, SalesLine WHERE SalesOrder.OrderNumber = SalesLine.OrderNumber GROUP BY SalesOrder.OrderNumber

Doesn't that works??

Posted by Etienne Begin on 28-Aug-2018 08:46

You can only use a column name or expression.  An expression can be an aggregate (min/max) or scalar function such as year/replace/trim.  Note that also means you can use hardcoded string values like

select "stringname" as 'column1'

No sub-queries.

You should work to find a way to avoid using a subquery.  It seems possible from your example.

Etienne

This thread is closed