Subject Re: [firebird-support] Aggregating a Union
Author Gordon Niessen
On 6/8/2011 10:08 AM, Gordon Niessen wrote:
>
> I am using FB1.5 and am trying to do a GROUP BY on the result of a
> UNION, but some how the syntax is eluding me.
>
> SELECT IC.item_id, IC.item_desc, SUM(IC1.qty), SUM(IC1.cost),
> SUM(IC1.ext_cost)
> FROM (
> SELECT IC1.item_id, IC1.item_desc, -IC1.qty, -IC1.cost, -IC1.ext_cost
> FROM ItemCost(12345) IC1
> UNION
> SELECT IC2.item_id, IC2.item_desc, IC1.qty, IC1.cost, IC1.ext_cost
> FROM ItemCost(12350) IC2
> ) IC
> GROUP BY IC.item_id, IC.item_desc
>
> Do I have to embed the union set in a Stored Procedure to later do the
> GROUP BY? I can't use a CASE on the qty, cost, and ext_cost by Order_ID
> as the actual ItemCost is actually a Stored Procedure call and it does
> not return Order_ID.
>
> Or is this not possible in FB1.5? How about FB2.5?
>
>
>
I have confirmed it works in 2.5, but I need a solution for FB1.5 for a
number of customers.

--
Thanks,

Gordon



[Non-text portions of this message have been removed]