Avatar of sam2929
sam2929

asked on 

roll up

Hi,
I have
Source:
Rq_id    event_id   event_code       cust number
1001        create          create              1005
1001         out              
1001         scucess       pickup             2001

So we want to roll up what we want is
Target will have just one row
Rq_id    event_id   event_code       cust number
1001       create         pickup               2001

So basic idea is pickup a row with event_id create and event_code pickup and cust number 2001 and then rollup it to one line only
DB2

Avatar of undefined
Last Comment
Kent Olsen
Avatar of Sharath S
Sharath S
Flag of United States of America image

I don't understand fully. Do you want this?

select * from your_table where cust_number = 2001 and event_code = 'pickup'
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sam2929
sam2929

ASKER

Thanks
what if i want sumthing like this
Source:
Rq_id    event_id   event_code       cust number        flag
1001        create          create              1005  
1001         out              
1001         sucess       pickup             2001      
1001         dump                                                                 Y

Result
Rq_id    event_id   event_code       cust number    flag
1001       create         pickup               2001            Y

Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image


Yep.  Just pick the correct fields (columns) from the query above.  Not sure how you're generating "flag".


Kent

SELECT t0.rq_id, t0.event_id, t1.event_code, t0.cust_number
FROM mytable t0
LEFT JOIN mytable t1
  ON t0.rq_id = t1.rq_id
 AND t0.event_id = 'create'
 AND t1.event_code = 'pickup'

Open in new window

DB2
DB2

IBM DB2 is a family of relational database server products developed by IBM that have been extended to support object-relational features and non-relational structures like JSON and XML. There are three main products in the DB2 family: DB2 for Linux, UNIX and Windows (informally known as DB2 LUW), DB2 for z/OS (mainframe), and DB2 for i (formerly OS/400), plus a version for IBM's Virtual Storage Extended (VSE) operating system.

6K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo