Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > Ask for help fr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 15 Topic 8958 of 9520
Post > Topic >>

Ask for help from ORACLE board: matching normalized and denormalized tables

by "lenygold via DBMonster.com" <u41482@[EMAIL PROTECTED] > Jun 9, 2008 at 08:55 PM

I found this problem on ORACLE board.
2 input TABLES:

Items
Id  ItemName
 1   Phone
 2   Table
 3   Lamp
 4   TV
 5   Stereo

ItemsByRooms
Id  Room      RoomItems
 1   Bedroom   Phone, Lamp, Bed, TV
 2   Kitchen   Phone, Table
 3   LvRoom    Phone, Lamp, TV, Stereo

Expected result:
Results would be:

Id  ItemName  QtyUsed
 1   Phone         3
 2   Table          1
 3   Lamp          2
 4   TV              2
 5   Stereo        1

This Problem wasn't resolved by ORACLE board members.

Here is my solution:
WITH T1 (Id,Room,RoomItems) AS
 (VALUES(1, 'Bedroom', 'Phone, Lamp, Bed, TV'),
        (2, 'Kitchen',  'Phone, Table'),
        (3, 'LvRoom',  'Phone, Lamp, TV, Stereo')),
     T2(Id,  ItemName) AS
  (VALUES(1, 'Phone'),
         (2, 'Table'),
         (3, 'Lamp'),
         (4, 'TV'),
         (5, 'Stereo'))
  SELECT  CHAR(T2.ID)|| '  '||ITEMNAME  "ID  ITEM_NAME"  ,count(*) AS
QTY_USED
    FROM T1,T2
     WHERE (LENGTH(STRIP(RoomItems)) - LENGTH(REPLACE(STRIP(RoomItems),
ITEMNAME,''))) > 0 
    GROUP BY CHAR(T2.ID)|| '  '||ITEMNAME;

ID  ITEM_NAME       QTY_USED   
-------------------              -----------
1            Phone                3
2            Table                 1
3            Lamp                 2
4            TV                     2
5            Stereo               1

  5 record(s) selected.

Is there is another solutions? 
For example using Recursion.
Thank's in advance Leny G.

-- 
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/ibm-db2/200806/1
 




 15 Posts in Topic:
Ask for help from ORACLE board: matching normalized and denormal
"lenygold via DBMons  2008-06-09 20:55:03 
Re: Ask for help from ORACLE board: matching normalized and deno
"Dave Hughes" &  2008-06-09 17:26:45 
Re: Ask for help from ORACLE board: matching normalized and deno
"lenygold via DBMons  2008-06-09 23:19:44 
Re: Ask for help from ORACLE board: matching normalized and deno
"lenygold via DBMons  2008-06-10 00:02:47 
Re: Ask for help from ORACLE board: matching normalized and deno
"Dave Hughes" &  2008-06-10 03:50:03 
Re: Ask for help from ORACLE board: matching normalized and
Tonkuma <tonkuma@[EMAI  2008-06-09 22:55:36 
Re: Ask for help from ORACLE board: matching normalized and deno
"Dave Hughes" &  2008-06-10 04:00:48 
Re: Ask for help from ORACLE board: matching normalized and
Tonkuma <tonkuma@[EMAI  2008-06-10 04:22:46 
Re: Ask for help from ORACLE board: matching normalized and deno
"Dave Hughes" &  2008-06-10 07:17:53 
Re: Ask for help from ORACLE board: matching normalized and deno
"Dave Hughes" &  2008-06-10 10:33:57 
Re: Ask for help from ORACLE board: matching normalized and
Tonkuma <tonkuma@[EMAI  2008-06-10 04:34:28 
Re: Ask for help from ORACLE board: matching normalized and
Tonkuma <tonkuma@[EMAI  2008-06-10 05:31:13 
Re: Ask for help from ORACLE board: matching normalized and
Tonkuma <tonkuma@[EMAI  2008-06-09 23:05:12 
Re: Ask for help from ORACLE board: matching normalized and
Tonkuma <tonkuma@[EMAI  2008-06-09 23:21:43 
Re: Ask for help from ORACLE board: matching normalized and
Philipp Post <Post.Phi  2008-06-10 02:47:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 20:52:23 CST 2008.