How to print the output of select query Horizontally?

Moderator: NorbertKrupa

Post Reply
atul.pdm@gmail.com
Newbie
Newbie
Posts: 7
Joined: Wed Oct 26, 2016 5:12 pm

How to print the output of select query Horizontally?

Post by atul.pdm@gmail.com » Mon Nov 21, 2016 2:38 pm

I need the output horizontally, union function gives the output in one column.
I am using below query, do I need to use join?Please suggest

Code: Select all

SELECT min(TIMESTAMPDIFF('ss',submission_time,start_time))as Min_Wait_time from time
union
SELECT max(TIMESTAMPDIFF('ss',submission_time,start_time))as Max_Wait_time from time
union
SELECT avg(TIMESTAMPDIFF('ss',submission_time,start_time))as Avg_Wait_time from time
union
SELECT median(TIMESTAMPDIFF('ss',submission_time,start_time)) over() as Median_wait_time from time
union

I am getting the output like:

Min_Wait_time
16.159641811159
5.0
0.0
115431.0
3737.53128

The output should be like:
Min_Wait_time   Max_Wait_time    Avg_Wait_time    Median_wait_time
0.0                   115431.0           16.159641811159       5.0




User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1768
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: How to print the output of select query Horizontally?

Post by JimKnicely » Mon Nov 21, 2016 3:29 pm

Maybe something like this?

Code: Select all

SELECT min(Wait_time) as Min_Wait_time,
       max(Wait_time) as Max_Wait_time,
       avg(Wait_time) as Avg_Wait_time,
	   max(Median_wait_time) as Median_wait_time
  FROM (SELECT TIMESTAMPDIFF('ss',submission_time,start_time) as Wait_time,
               median(TIMESTAMPDIFF('ss',submission_time,start_time)) over() as Median_Wait_time
          FROM acctn) foo;
Jim Knicely

Image

Note: I work for HPE. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “New to Vertica SQL”