BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MySQL syntax for an inverted table

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop)
View previous topic :: View next topic  
Author Message
Colin B Maharaj
Guest





PostPosted: Mon Oct 02, 2006 4:30 am    Post subject: MySQL syntax for an inverted table Reply with quote



I have this query (and result)...

select desttype A, sum(duration) B,
count(cost) C, sum(cost) D from calls
group by desttype;
+------+----------+--------+---------+
| A | B | C | D |
+------+----------+--------+---------+
| NULL | 20179324 | 122048 | 0.00 |
| AR | 13155339 | 70456 | 0.00 |
| CE | 1385003 | 16232 | 0.00 |
| IT | 86003 | 292 | 1814.60 |
| LD | 526292 | 2213 | 7438.29 |
| LO | 261093 | 557 | 0.00 |
| SD | 8684 | 41 | 643.50 |
+------+----------+--------+---------+
7 rows in set (0.56 sec)

But I want to turn it "90 degrees" i.e. make the tuples into columns and
the columns into tuples. So far this is what I have come up with,
partially......


select * from
(select sum(cost) AR from calls where desttype='AR') as tmp1,
(select sum(cost) LO from calls where desttype='LO') as tmp2,
(select sum(cost) LD from calls where desttype='LD') as tmp3,
(select sum(cost) IT from calls where desttype='IT') as tmp4;

+------+------+---------+---------+
| AR | LO | LD | IT |
+------+------+---------+---------+
| 0.00 | 0.00 | 7438.29 | 1814.60 |
+------+------+---------+---------+
1 row in set (1.05 sec)

But I think this is way too much processing and this is just the cost part.
Any advice would be nice. I am using MySQL 5x.
Back to top
Jayme Jeffman
Guest





PostPosted: Mon Oct 02, 2006 11:43 pm    Post subject: Re: MySQL syntax for an inverted table Reply with quote



Hi,

I am afraid there is not another way of doing this. As far as I know
the SQL language is thought for retrieve column values from tables
as rows.

HTH

Jayme.

"Colin B Maharaj" <noreply (AT) myhost (DOT) com> escreveu na mensagem
news:45204f6a (AT) newsgroups (DOT) borland.com...
Quote:
I have this query (and result)...

select desttype A, sum(duration) B,
count(cost) C, sum(cost) D from calls
group by desttype;
+------+----------+--------+---------+
| A | B | C | D |
+------+----------+--------+---------+
| NULL | 20179324 | 122048 | 0.00 |
| AR | 13155339 | 70456 | 0.00 |
| CE | 1385003 | 16232 | 0.00 |
| IT | 86003 | 292 | 1814.60 |
| LD | 526292 | 2213 | 7438.29 |
| LO | 261093 | 557 | 0.00 |
| SD | 8684 | 41 | 643.50 |
+------+----------+--------+---------+
7 rows in set (0.56 sec)

But I want to turn it "90 degrees" i.e. make the tuples into columns and
the columns into tuples. So far this is what I have come up with,
partially......


select * from
(select sum(cost) AR from calls where desttype='AR') as tmp1,
(select sum(cost) LO from calls where desttype='LO') as tmp2,
(select sum(cost) LD from calls where desttype='LD') as tmp3,
(select sum(cost) IT from calls where desttype='IT') as tmp4;

+------+------+---------+---------+
| AR | LO | LD | IT |
+------+------+---------+---------+
| 0.00 | 0.00 | 7438.29 | 1814.60 |
+------+------+---------+---------+
1 row in set (1.05 sec)

But I think this is way too much processing and this is just the cost
part.
Any advice would be nice. I am using MySQL 5x.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.