Subject | Re: [firebird-support] How do you 0/null results to a GROUP BY query |
---|---|
Author | Alexandre Benson Smith |
Post date | 2012-10-24T22:07:05Z |
try something like this:
with recursive
Datas (Data) as
(select
Cast('2009-01-01' as Date)
From
rdb$database
union all
Select
Data + 1
From
Datas
Where
Data + 1 <= Cast('2009-01-31' as Date))
select
D.Data, sum(PVI.QuantidadeOriginal)
from
Datas D left join
PedidoVendaItem PVI on (D.Data = PVI.DataEntrega)
group by
D.Data
change the field/table names to fit you needs
HTH
Em 24/10/2012 19:54, cornievs escreveu:
with recursive
Datas (Data) as
(select
Cast('2009-01-01' as Date)
From
rdb$database
union all
Select
Data + 1
From
Datas
Where
Data + 1 <= Cast('2009-01-31' as Date))
select
D.Data, sum(PVI.QuantidadeOriginal)
from
Datas D left join
PedidoVendaItem PVI on (D.Data = PVI.DataEntrega)
group by
D.Data
change the field/table names to fit you needs
HTH
Em 24/10/2012 19:54, cornievs escreveu:
> Hi All
>
> I have query which extract the sales per day from a table
>
> Select EXTRACT(YEAR from DT) as YEARNO, EXTRACT(YEARDAY from DT) AS DAYNO, SUM(DUE) from CLIENT_INVOICES group by YEARNO, WEEKNO.
>
> It works 100%, but only returns the dates with sales, I need it to also include the dates with zero sales, for example:
>
> YEARNO DAYNO SUM
> 2012 01 5000
> 2012 02 6000
> 2012 03 0 (or null will be fine)
> 2012 04 7000
>
> etc.
>
> Any help will be appreciated!
>
> Cornie van Schoor
> InfoStar Software
>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>
>