473,387 Members | 3,820 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,387 software developers and data experts.

convert rows to columns

Hi All,

I want following o/p in oracle & sql server

a table contains data as given

name exam marks
-------- -------- -----------
Test Phy 30
Test Chm 40
Test Eng 50
XYZ Eng 50
XYZ Mat 11
XYZ SS 10
XYZ Phy 40


Final O/p ->

Name Sub1 mark1 sub2 mark2 sub3 mark3 sub4 mark4
-------- -------- -------- --------- -------- ------- --------- -------- --------
Test Phy 30 Chm 40 Eng 50
XYZ Eng 50 Mat 11 SS 10 Phy 40


pls send me query
Jan 30 '07 #1
2 9893
Hi All,

I want following o/p in oracle & sql server

a table contains data as given

name exam marks
-------- -------- -----------
Test Phy 30
Test Chm 40
Test Eng 50
XYZ Eng 50
XYZ Mat 11
XYZ SS 10
XYZ Phy 40


Final O/p ->

Name Sub1 mark1 sub2 mark2 sub3 mark3 sub4 mark4
-------- -------- -------- --------- -------- ------- --------- -------- --------
Test Phy 30 Chm 40 Eng 50
XYZ Eng 50 Mat 11 SS 10 Phy 40


pls send me query

hi Please find the query below

select name
, max (case exam when 'Chm' then exam end) as Sub1
, max (case exam when 'Chm' then marks end) as Mark1
, max (case exam when 'Eng' then exam end) as Sub2
, max (case exam when 'Eng' then marks end) as Mark2
, max (case exam when 'Mat' then exam end) as Sub3
, max (case exam when 'Mat' then marks end) as Mark3
, max (case exam when 'Phy' then exam end) as Sub4
, max (case exam when 'Phy' then marks end) as Mark4
, max (case exam when 'SS' then exam end) as Sub5
, max (case exam when 'SS' then marks end) as Mark5
from t
group by name;
May 23 '07 #2
frozenmist
179 Expert 100+
Hi,
Please read through the Posting Guidelines before posting.
Please don't ask for the query unless you have tried it out and have posted your version of the query.
The experts are more than happy to help you out with your queries, but you should post your attempt first.
Please be careful in future.

Thanks,
MODERATOR
May 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: helpful sql | last post by:
Hi all, I am using an HTML table control on my ASP.Net page. Now I need to change this table so that columns become rows and rows become column. Since the table is very complex with many controls...
1
by: blah1234 | last post by:
Is there anyway in DB2 to convert rows to columns? In other words, if I have the following table below... MemberID AccountNum ZipCode ------------------------------------ 1234 1...
1
by: Stan Sainte-Rose | last post by:
Oopps sorry for the previous post. As I said, I m trying to make a web custom control and I do know how I have to convert this part to for the render section In fact it may be a stupid...
0
by: helpful sql | last post by:
Hi all, I am using an HTML table control on my ASP.Net page. Now I need to change this table so that columns become rows and rows become column. Since the table is very complex with many controls...
0
by: Harry Haller | last post by:
The context is shown below in the getGames() method. I get errors on these lines: dtGames.Rows = (TimeSpan)dtGames.Rows; dtGames.Rows = (DayOfWeek)dtGames.Rows; because the playDate column...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
9
by: dotnetguru | last post by:
Hi SMART GUYS, Please help me write a query. Actually I want to convert my rows into columns. Can anyone kindly give me the query to do it? My rows are about employees. There can be any number of...
3
by: italia | last post by:
I have a database with 2 columns and more than million rows. The first column is the id Example of the data (2 columns)- 04731 CRM 04731 CRM 04731 CRM 04731 RVB 04731 RVB
4
by: RICALJE | last post by:
Hi All, Could you help me in my problem in working on a project that imports excel file to a datatable the validation is to catch all null values in the excel file because it will should not allow...
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.