Subject Re: [firebird-support] SQL Question
Author Arno Brinkman
Hi Michael,

> If I have a table containing (among others) theese records:
>
> Color Size Number
> AA XX 1
> AA YY 2
> AA ZZ 3
> BB XX 4
> BB YY 5
> BB ZZ 6
>
> Can I then make a select that will return something like:
>
> XX YY ZZ
> AA 1 2 3
> BB 4 5 6

Not dynamic, if you need it for a print-report may be it's easier to solve
with the rapport-tool.

SELECT
t1.Color,
(SELECT Count(*) FROM TableX t2 WHERE t2.Color = t1.Color and t2.Size =
'XX') AS XX,
(SELECT Count(*) FROM TableX t2 WHERE t2.Color = t1.Color and t2.Size =
'YY') AS YY,
(SELECT Count(*) FROM TableX t2 WHERE t2.Color = t1.Color and t2.Size =
'ZZ') AS ZZ
FROM
TableX t1
GROUP BY
t1.Color

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info