List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:September 22 1999 11:22pm
Subject:Re: Crosstable
View as plain text  
On Tue, 1999-09-21 17:29:07 -0500, Arun Bhalla wrote:
> Something like this should do:
> 
> SELECT color, size, COUNT(size = 'S') AS S, COUNT(size = 'M') AS M, 
>   COUNT(size = 'L') AS L FROM shirttable GROUP BY color, size

Almost!

SELECT
    color
  , SUM(IF(size='S',amount,0)) as S
  , SUM(IF(size='M',amount,0)) AS M
  , SUM(IF(size='L',amount,0)) AS L
FROM shirttable
GROUP BY color;

> Eric Zwart writes:
> > This is what I want to do:
> > 
> > +--------+------+--------+
> > | color      | size    | amount |
> > +--------+------+--------+
> > | blue       |    S    |      1     |
> > | blue       |    M   |      2     |
> > | blue       |    L    |      3     |
> > | red        |    S     |     4     |
> > | red        |    M    |    5     |
> > | red        |    L     |     6     |
> > | yellow   |    S     |     7     |
> > | yellow   |    M    |     8     |
> > | yellow   |    L     |     9      |
> > +--------+------+------- +
> > becomes
> > +--------+------+------+------+
> > | color      |    S    |   M    |   L     |
> > +--------+------+------+------+
> > | blue       |    1     |    2    |    3    |
> > | red        |    4     |    5    |    6    |
> > | yellow    |    7    |    8    |    9     |
> > +--------+------+------+------+

Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
CrosstableEric Zwart21 Sep
  • Re: CrosstableMartin Ramsch21 Sep
  • Re: CrosstableEric Zwart22 Sep
    • Re: CrosstableArun Bhalla22 Sep
      • Re: CrosstableMartin Ramsch23 Sep
        • triggering an event, by defaultVenky23 Sep