× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



1) except that DB doesn't know ahead of time they're unique, so it'll do
(now extraneous) DISTINCT processing anyway, incurring overhead
unnecessarily

V6R1 does provide the enhancements you mentioned. See:

http://publib.boulder.ibm.com/infocenter/systems/scope/i5os/topic/db2/rbafzg
roupbyclause.htm?tocNode=int_224745

HTH, Elvis

Celebrating 11-Years of SQL Performance Excellence on IBM i, i5/OS and
OS/400
www.centerfieldtechnology.com


-----Original Message-----
Subject: RE: Rollup SQL function for v5r4?

Thanks Chuck and Elvis.

1. Union vs. union all is fine in this case, as the detail is already
unique by item.
2. Both of the solutions presented require what Elvis called a helper
column for collating. Adding such a column allows for order by 1,2 which
is the desired result.
3. I agree with the sorting explanation. Whether it always holds true,
I've found that multiple unioned statements are generally presented in
top-down order when the ORDER BY is omitted.
4. The equivalent (untested) statement in SQL server syntax is something
like
Select coalesce(item,'Total'), sum(workamount), sum(loadamount),
sum(difference), sum(diffround)
From temp2
Group by item with rollup

This will subtotal and sort by item number. In effect, SQL server sorts
data by each of the columns in the rollup. One could also add ORDER BY
GROUPING(ITEM),ITEM if desired. The function grouping(column) returns 0
if a detail row, or 1 if a grouped row. When grouping(item) is 1, that
is the summarizing group, and the item column is null.

I have not looked but perhaps V6R1 supports WITH ROLLUP or the DB2
syntax ROLLUP() and GROUPING SETS() syntax.

Loyd Goodbar



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.