Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:50:50+00:00 2026-05-22T20:50:50+00:00

How do i transform the table of format based on the value in the

  • 0

How do i transform the table of format based on the value in the “Col1”
Let the initial table content be

Col1    Col2    Cnt     color
----------------------------
1       1       5       green
1       2       0       blue
1       3       7       red
2       1       0       gray
2       2       10      yellow
2       3       8       orange

INTO the table of following format

c11  d11  e11  color11  c12  d12 e12  color12  c13  d13 e13 color13
------------------------------------------- -----------------------
1    1    5  green       1   2    0    blue     1   3    7   red
2    1    0  gray        2   2    10   yellow   2   3    8   orange

the query is used to generate the data set for a report. where i plot the bubble chart for the each of the x,y co-ordinate.

” c11 d11 e11 c12 d12 e12 c13 d13 e13″ are the column names in the new dataset. Since the columns could vary dynamically i have quoted as this way.

I use the color to plot the color for each bubble value

Can some one please help in this query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:50:51+00:00Added an answer on May 22, 2026 at 8:50 pm

    I don’t think a PIVOT solution is what you’re really after. Instead you can do the following

    WITH TestData AS
    (
    SELECT 1 Col1, 1 Col2, 5 Cnt, 'green' color
    UNION SELECT 1 , 2 , 0 Cnt, 'blue'
    UNION SELECT 1 , 3 , 7 Cnt, 'red'
    UNION SELECT 2 , 1 , 0 Cnt, 'gray'
    UNION SELECT 2 , 2 , 10 Cnt, 'yellow'
    UNION SELECT 2 , 3 , 8 Cnt, 'orange'
    
    )
    SELECT 
        t1.col1 c11 , 
        t1.col2 d11 ,
        t1.cnt e11,
        t1.color  color11,
        t2.col1 c12   , 
        t2.col2 d12 ,
        t2.cnt e12,
        t2.color  color12  ,
        t3.col1 c13 , 
        t3.col2 d13 ,
        t3.cnt e13,
        t3.color  color13
    
    
    FROM 
        TestData t1
        inner join TestData t2 
        ON t1.Col1 = t2.Col1 
        inner join TestData t3 
        ON t1.Col1 = t3.Col1 
    where t1.Col2 = 1
        and t2.Col2 = 2
        and t3.Col2 = 3
    

    Which outputs this

    c11 d11 e11 color11 c12 d12 e12 color12 c13 d13 e13 color13
    --- --- --- ------- --- --- --- ------- --- --- --- -------
    1   1   5   green   1   2   0   blue    1   3   7   red
    2   1   0   gray    2   2   10  yellow  2   3   8   orange
    
    (2 row(s) affected)
    

    My guess is that you’ll probably need to Dynamically Generate this sql in your solution rather than the static solution I have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I transform a time value into YYYY-MM-DD format in Java? long lastmodified
Is empty lookup table the same as non-matching lookup table in lookup transform? What
How can I transform a String value into an InputStreamReader ?
I am using this javascript ( Super Table ) to transform my table in
I am using Python to read in data in a user-unfriendly format and transform
Basically idea is to grab data from MySQL table and transform it to JSON.
I'm trying to write a query that extracts and transforms data from a table
I have table with an auto-increment field, but I need to transfer the table
I have 2 databases, and I want to transport an existing table containing a
I want to transform an XML document. The source XML looks like this: <svc:ElementList>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.