473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Vertical data to Horizontal data

Hi,

I have some data in rows which I want them in columns. Below is an
example:

col1 col2 col3
------ ----- -----
table length 45
table breadth 50
table height 60
chair length 15
chair breadth 25
chair height 20

I want this data in this format:
col1 length breadth height
----- -------- ---------- --------
table 45 50 60
chair 15 25 20

Can someone help in getting this o/p using SQL queries?
Thanks.

Saurabh
Jan 14 '08 #1
3 5447
spider007 wrote:
Hi,

I have some data in rows which I want them in columns. Below is an
example:

col1 col2 col3
------ ----- -----
table length 45
table breadth 50
table height 60
chair length 15
chair breadth 25
chair height 20

I want this data in this format:
col1 length breadth height
----- -------- ---------- --------
table 45 50 60
chair 15 25 20

Can someone help in getting this o/p using SQL queries?
Thanks.

Saurabh
What you are looking for is called a "Pivot Query", and the best description
for it is in a presentation "SQL On Fire" given by Serge Rielau during the
European IDUG 2006.
Check this blog-entry from Chris Eaton's blog where Chris gives an example
based on Serge's material:

http://blogs.ittoolbox.com/database/...ot-query-12757

In a comment to that blog-entry I've given links to the "SQL On Fire"
material (pivoting is in part 1, iirc).

HTH

Cheers!

--
Jeroen
Jan 14 '08 #2
On Jan 14, 10:30 am, "The Boss" <use...@No.Spam.Please.invalidwrote:
spider007 wrote:
Hi,
I have some data in rows which I want them in columns. Below is an
example:
col1 col2 col3
------ ----- -----
table length 45
table breadth 50
table height 60
chair length 15
chair breadth 25
chair height 20
I want this data in this format:
col1 length breadth height
----- -------- ---------- --------
table 45 50 60
chair 15 25 20
Can someone help in getting this o/p using SQL queries?
Thanks.
Saurabh

What you are looking for is called a "Pivot Query", and the best description
for it is in a presentation "SQL On Fire" given by Serge Rielau during the
European IDUG 2006.
Check this blog-entry from Chris Eaton's blog where Chris gives an example
based on Serge's material:

http://blogs.ittoolbox.com/database/.../pivot-query-1...

In a comment to that blog-entry I've given links to the "SQL On Fire"
material (pivoting is in part 1, iirc).

HTH

Cheers!

--
Jeroen

Serge's presentations are also available here:

http://www.iiug.org/waiug/present/Fo...Forum2006.html

in the "DB2 Performance Tuning and Administration" section

--Jeff
Jan 14 '08 #3
On Jan 15, 12:39 am, jefftyzzer <jefftyz...@sbcglobal.netwrote:
On Jan 14, 10:30 am, "The Boss" <use...@No.Spam.Please.invalidwrote:
spider007 wrote:
Hi,
I have some data in rows which I want them in columns. Below is an
example:
col1 col2 col3
------ ----- -----
table length 45
table breadth 50
table height 60
chair length 15
chair breadth 25
chair height 20
I want this data in this format:
col1 length breadth height
----- -------- ---------- --------
table 45 50 60
chair 15 25 20
Can someone help in getting this o/p using SQL queries?
Thanks.
Saurabh
What you are looking for is called a "Pivot Query", and the best description
for it is in a presentation "SQL On Fire" given by Serge Rielau during the
European IDUG 2006.
Check this blog-entry from Chris Eaton's blog where Chris gives an example
based on Serge's material:
http://blogs.ittoolbox.com/database/.../pivot-query-1...
In a comment to that blog-entry I've given links to the "SQL On Fire"
material (pivoting is in part 1, iirc).
HTH
Cheers!
--
Jeroen

Serge's presentations are also available here:

http://www.iiug.org/waiug/present/Fo...Forum2006.html

in the "DB2 Performance Tuning and Administration" section

--Jeff
Great! Thanks guys! Really appreciate your help.

-Saurabh
Jan 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Harlan Messinger | last post by:
Is IE6 known to have a bug whereby a vertical table cell border (with border-collapse: collapse), instead of stopping at the bottom of a horizontal border, sticks up into it by one pixel? My other...
3
by: buht | last post by:
Hello Everyone, Fairly new to c# here and have a question regarding scrollbars, particularly a vertical scrollbar. It looks like my options are restricted for the textbox scrollbars being...
3
by: sumit | last post by:
Hi, I made a data grid vertically as well as horizontal scrollable as number of columns are very large!! But when i scroll horizontally then header is not visible as it also gets scrolled...
3
by: lolo | last post by:
hello. happy new year. I'm trying to build a website for my wife and she is adament on having a horizontal thumbnail scrolling div. great. I have a good vertical scrolling thing, but can't...
2
by: etangman | last post by:
This is proving more challenging than first thought. I have data in every 4 cells in a horizontal row and I need to copy that data to a vertical column with no interval. I've got this... I know it...
0
by: slakmagik | last post by:
Is there a way to declare horizontal positioning (without referring to or changing vertical) or vertical positioning (without referring to or changing horizontal) in a single declaration? ...
1
by: bai | last post by:
In my page, I have both horizontal and vertical scroll bars. I want to to some action on Vertical scrollbar click/move and some other action on horizontal scrollbar move/click. How to know whether...
8
by: ayamopamo | last post by:
Hi- I am trying to center a web page. It seems like this should be very simple to do, but apparently it isn't my day. I have successfully centered the background by calling it in the css body tag:...
4
by: sindhu | last post by:
Hello please some one tell me how to make a menu appear horizontal or vertical in javascript and css. I'm bugged up after searching for one factor that makkes a menu8 appear horizontal or vertical...
0
by: skoyala | last post by:
Hi All, I need to put a horizontal scroll bar for 4 cells alone where my first cell in table should not contain any horizontal scroll bar but i need to put vertical scroll bar to both first and 4...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.