Subject | RE: [firebird-support] SQL statment Help |
---|---|
Author | Leyne, Sean |
Post date | 2011-05-19T22:28:41Z |
> This may be the wrong group but I need some advice on a SQL statementIf you are using the Firebird v2.1 or later you should be able to:
>
> I have a database that tacks all sales by date and by product I would like to
> run a function to display the products with a summary of the items per
>
> Day for example
>
> Item 01/05/11 02/05/11
> 03/05/11
>
> =====================================================
>
> VALUE ORANGE JUICE 5 9
> 10
SELECT
Sales.Product_Desc,
CASE WHEN (Sales.ItemDate = '1 MAY 2011') THEN COALESCE( Sales.ItemCount, 0) ELSE 0 END as Col1,
CASE WHEN (Sales.ItemDate = '2 MAY 2011') THEN COALESCE( Sales.ItemCount, 0) ELSE 0 END as Col2,
CASE WHEN (Sales.ItemDate = '3 MAY 2011') THEN COALESCE( Sales.ItemCount, 0) ELSE 0 END as Col3
FROM (
SELECT
Product_Desc,
ItemDate,
SUM( ItemCount) as ItemCount
FROM ItemSales
WHERE
ItemDate BETWEEN '1 MAY 2011' AND '3 MAY 2011'
GROUP BY 1, 2
) as Sales
ORDER BY 1