× 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.



In V6R1 there are now grouping extensions - like ROLLUP and CUBE - I've not used them, and the reference manual does not help me much yet - but this is intriguing

CUBE ( grouping-expression-list )
A CUBE grouping is an extension to the GROUP BY clause that produces a result set that contains all the rows of a ROLLUP aggregation and, in addition, contains ″cross-tabulation″ rows. Cross-tabulation rows are additional ″super-aggregate″ rows that are not part of an aggregation with sub-totals.

Charles Wilt wrote:
No, DB2 UDB for i5/OS doesn't have a cross-tab/pivot table function built in.

Web query is probably your best bet.

However, you can actually manually perform the cross-tab function
using the CASE statement.

Given:

Period Category Sales
2002-01 Snacks 3000.25
2002-01 Beverages 2145.01
2002-01 Fruit 175.20
2002-02 Snacks 2167.40
2002-02 Beverages 2022.39

Select Period,
Sum(Case When Category='Beverages'
Then SalesAmt End) As Beverages,
Sum(Case When Category='Fruit'
Then SalesAmt End) As Fruit,
Sum(Case When Category='Snacks'
Then SalesAmt End) As Snacks
From Sales
Group By Period
Order By Period

Gives you:
Period Beverages Fruit Snacks
2002-01 2145.01 175.20 3000.25
2002-02 2022.39 -- 2167.40



In addition, on the web you'll find various utilities developers have
written to automate this process so that you don't have to know ahead
of time how many columns you'll need.

Here's one, (from which I took the above example)
http://www.itjungle.com/mpo/mpo032703-story01.html

HTH,
Charles


On Thu, Dec 18, 2008 at 8:29 AM, Jerry Adams <Jerry@xxxxxxxxxxxxxxx> wrote:
My boss (the PC server guy) asked me if System i's SQL had a cross tab function. Never heard of it, but he said it was like a pivot table.

My searches in the SQL manuals, Info Center, and the srchives only turned up a reference in the IC to OLAP in Web Query for DB2.

Is there a cross tab function in SQL? We do have 5722-ST1 (DB2 Query Mgr and SQL DevKit) installed.

Thanks.

Jerry C. Adams
IBM System i Programmer/Analyst
B&W Wholesale
office: 615-995-7024
email: jerry@xxxxxxxxxxxxxxx

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


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.