473,763 Members | 9,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5486
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.invalid wrote:
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...@sbc global.netwrote :
On Jan 14, 10:30 am, "The Boss" <use...@No.Spam .Please.invalid wrote:
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
2042
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 browsers display horizontal borders as lying over vertical borders. IE6 *almost* does this, with the vertical border encroaching into the horizontal by the one pixel. -- Harlan Messinger Remove the first dot from my e-mail address. Veuillez...
3
9901
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 that I can enable vertical or horizontal scrollbars for the textbox and their wrapping but thats it for modifications of the scrollbar.
3
3296
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 up,,so to tackle this i made a different data grid having only header as the row and the other datagrid contains the actual data for it,, Due to this vertical scrolling problem goes as i have put
3
5395
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 figure out how to make it scroll horizontally. It's probably real simple and I just can't figure it out.... Here is the code I have so far:
2
1382
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 doesn't work but it should be something like this I would think. Dim nRow1 As Integer Dim i As Integer nRow = 3 For i = 3 To 15 Step 4
0
1607
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? foo-left and foo-right will specify the horizontals in two declarations, but bar { foo: auto 1em; } sometimes results in the vertical changing. Is there no 'as-is' in place of 'auto'? Actual 'horizontal' and 'vertical' keywords to go with...
1
3663
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 the click is on horizontal or vertical scrollbar?
8
3553
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: body { font-family: Trebuchet MS, Arial; cursor : default; background:#000000 url("Images/long-template.jpg"); background-repeat:no-repeat; background-position: center; background-attachment:scroll; height: 1228px;
4
2507
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 please someone.......... thanks in advance
0
1716
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 cells.both first and 4 cells should scroll vertically but 4 cells only scroll horizontally In clear, let us say there are 5 columns in my table i want to put horizontal scroll bar only for 2nd,3rd,4th and 5th column alone where my 1st column...
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.