Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

db2 olap functions combining two rows into one

Posted on 2015-02-20
3
Medium Priority
?
215 Views
Last Modified: 2015-02-23
I am trying to find a olap function that will combine two rows into one.  I have a field that I can group by on but the indicators I would like to crosstab.  Combining the two rows into one.  I will attach a sample file.
0
Comment
Question by:centralmike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 40621870
i don't see an attachment

you can use xmlagg to pull multiple rows and columns into one value

then use xml parsing function to pull the fields into individual columns within a single row
0
 

Author Comment

by:centralmike
ID: 40621949
I will send again
OLAP-SAMPLE.docx
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 40622067
for something like that, it's even simpler, just do conditional aggregation


  SELECT messge_group_id,
         MAX(CASE WHEN debit_credit_ind = 'D' THEN amount END) debit_amt,
         MAX(CASE WHEN debit_credit_ind = 'C' THEN amount END) credit_amt
    FROM table1
GROUP BY message_group_id
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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