DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Help with Transpose Query

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Help with Transpose Query

    Hi,

    I just put in a sample tables here. I also put in a sample output.

    Could someone help how to write a query to get a output like that.

    Table -1 - product

    productid name type

    1 YYYYY Laptop
    2 N900 Phone
    3 IPAD Tablet



    Table 2 - productdetails


    productid attribute value

    1 RAM 5GB
    1 Processor i7
    1 video 1080p
    2 processor omap
    2 RAM 32GB
    2 video 320p
    3 RAM 1GB
    3 Processor coreduo
    3 video 720p


    i need an output like this
    ****************************

    productid productname type RAM PROCESSOR
    1 ASUS LAptop 4GB i7

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Output data is not even part of described tables.

    Is this homework? - Teacher is talking about joins, isn't it?

    What do you have so far?
    Last edited by PAVB; 02-21-2011 at 03:48 PM. Reason: typo
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    Feb 2011
    Posts
    6
    SELECT P1.PRODUCTID,
    p1.name,
    p1.TYPE,
    ram.ATTRIBUTE ram,
    ram.VALUE ramvalue,
    proc.attribute proc,
    proc.VALUE procvalue,
    vid.attribute video,
    vid.value videovalue
    FROM product P1,
    (SELECT VALUE, attribute, productid
    FROM productdetails
    WHERE upper(attribute) = upper('ram')) ram,
    (SELECT VALUE, attribute, productid
    FROM productdetails
    WHERE UPPER (attribute) = UPPER ('processor')) proc,
    (SELECT VALUE, attribute, productid
    FROM productdetails
    WHERE UPPER (attribute) = UPPER ('video')) vid
    WHERE p1.productid = ram.productid
    AND proc.productid = p1.productid
    and vid.productid = p1.productid

  4. #4
    Join Date
    Feb 2011
    Posts
    6
    Quote Originally Posted by rrdbala View Post
    Hi,

    I just put in a sample tables here. I also put in a sample output.

    Could someone help how to write a query to get a output like that.

    Table -1 - product

    productid name type

    1 YYYYY Laptop
    2 N900 Phone
    3 IPAD Tablet



    Table 2 - productdetails


    productid attribute value

    1 RAM 5GB
    1 Processor i7
    1 video 1080p
    2 processor omap
    2 RAM 32GB
    2 video 320p
    3 RAM 1GB
    3 Processor coreduo
    3 video 720p


    i need an output like this
    ****************************

    productid productname type RAM PROCESSOR
    1 ASUS LAptop 4GB i7
    test

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width