Subject | Re: [ib-support] Newbie qu's |
---|---|
Author | Arno Brinkman |
Post date | 2003-04-24T23:08:13Z |
Hi,
In Firebird 1.5 you can also use the CASE expression :
SELECT
'Total',
SUM(CASE WHEN Kiosks.Name='desktop'
THEN Metrics.Copies ELSE 0 END) AS 'desktop',
SUM(CASE WHEN Kiosks.Name='redcoat3'
THEN Metrics.Copies ELSE 0 END) AS 'redcoat3',
SUM(Metrics.Copies) as Total
FROM
Kiosks
INNER JOIN Metrics ON (Kiosks.ID=Metrics.Kiosk_Id)
WHERE
Time IS NOT NULL AND Copies IS NOT NULL
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Nederlandse firebird nieuwsgroep :
news://80.126.130.81
> - is there anywhere I can download documentation on the FirebirdLook at : http://www.ibphoenix.com/
> keywords and how to use them eg LEFT, IN etc..
> - in mySQL I simulated a crosstab query (eg from MS Access) byAs already somebody said you can use a stored procedure.
> getting the column names, and then creating a query like this to
> return the report table in one swoop:
>
> SELECT 'Total', SUM(IF(Kiosks.Name='desktop', Metrics.Copies,
> 0)) AS 'desktop', SUM(IF(Kiosks.Name='redcoat3', Metrics.Copies, 0))
> AS 'redcoat3', SUM(Metrics.Copies) as Total FROM Kiosks INNER JOIN
> Metrics ON Kiosks.ID=Metrics.Kiosk_Id WHERE Time IS NOT NULL AND
> Copies IS NOT NULL
>
> Is this possible in Firebird, and if not, can anyone suggest another
> method?
In Firebird 1.5 you can also use the CASE expression :
SELECT
'Total',
SUM(CASE WHEN Kiosks.Name='desktop'
THEN Metrics.Copies ELSE 0 END) AS 'desktop',
SUM(CASE WHEN Kiosks.Name='redcoat3'
THEN Metrics.Copies ELSE 0 END) AS 'redcoat3',
SUM(Metrics.Copies) as Total
FROM
Kiosks
INNER JOIN Metrics ON (Kiosks.ID=Metrics.Kiosk_Id)
WHERE
Time IS NOT NULL AND Copies IS NOT NULL
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Nederlandse firebird nieuwsgroep :
news://80.126.130.81