dbTalk Databases Forums  

Need Help with Crosstab query

comp.databases comp.databases


Discuss Need Help with Crosstab query in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lemune
 
Posts: n/a

Default Need Help with Crosstab query - 07-02-2006 , 08:57 PM






Hello everyone. My problem is I want to make a query that will produce
table that look like crosstab report. My table is tblTransaction with
field Name, DateTimeHappened, Duration, ConnectionType. ConnectionType
will have 4 value: Local, Interlocal, International and Unknown. I want
make crosstab that will calculate total duration on each person and
will show the total duration on each type of connection and if possible
it will sort (order by) by Total duration.
Thanks in advance


Reply With Quote
  #2  
Old   
Dieter Noeth
 
Posts: n/a

Default Re: Need Help with Crosstab query - 07-03-2006 , 02:12 AM






Lemune wrote:

Quote:
Hello everyone. My problem is I want to make a query that will produce
table that look like crosstab report. My table is tblTransaction with
field Name, DateTimeHappened, Duration, ConnectionType. ConnectionType
will have 4 value: Local, Interlocal, International and Unknown. I want
make crosstab that will calculate total duration on each person and
will show the total duration on each type of connection and if possible
it will sort (order by) by Total duration.
select
name,
sum(duration) as "total",
sum(case when connectiontype = 'local' then Duration end) as "local",
sum(case when connectiontype = 'interlocal' then Duration end) as
"interlocal",
...
from tab
group by name
order by sum(duration) desc

Dieter


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.