-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: transpose table rows to columns
PostPosted: Sat Oct 03, 2009 8:10 am 
Newbie

Joined: Sat Oct 03, 2009 7:45 am
Posts: 1
I have table with data as below
columnname: name| start_time| download_time
row1: 'Home Page'| '2009-09-23 00:06:28'| 25
row2: 'Hotmail Home Page'| '2009-09-21 14:20:20'| 25
row3: 'Logout Page'| '2009-09-23 00:06:28'| 1
row4: 'Netbanking After Login Page'| '2009-09-23 00:06:28'| 6
row5: 'Home Page'| '2009-09-23 00:08:53'| 0
row6: 'Netbanking After Login Page'| '2009-09-23 00:08:53'| 0

i have to transpose this table in to something like this.


columnnames: name |2009-09-23 00:06:28 | 2009-09-23 00:08:53 |2009-09-23 00:11:01
row1 'Home Page' | 25 | 0 | 0
row2 'Hotmail Home Page'| 0 |0|0
row3 'Logout Page'| 1| 0| 0
row4 'Netbanking After Login Page' | 6| 0| 0


this i could achive using below select statement.
select s.name,
SUM(case when s.start_time= '2009-09-23 00:06:28' then s.download_time end) as '2009-09-23 00:06:28',
SUM(case when s.start_time= '2009-09-23 00:08:53' then s.download_time end) as '2009-09-23 00:08:53',
SUM(case when s.start_time= '2009-09-23 00:08:53' then s.download_time end) as '2009-09-23 00:11:01'
from script_info s group by s.name


Now i want to map this in hibernate. how i can do this?

Best Regards
krishna


Top
 Profile  
 
 Post subject: Re: transpose table rows to columns
PostPosted: Mon Oct 05, 2009 2:03 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Hi,
I don't know what database you are using. Does your database support column names with dashes and colons (2009-09-23 00:06:28)? Also is'nt it that the column names are dynamic as they represent timestamp?
Not sure what you are trying to do.
-Srilatha.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.