On 6/4/07, Tatu <[EMAIL PROTECTED]> wrote:

Tenho 2 tabelas, NFc e NFi, como segue:

NFc.nronf,
NFc.dataem,
etc..etc..

NFi.nronf,
NFi.iten,
NFi.quantidade
etc...etc..

Necesito poder agrupar, dentro do mesmo mes, de tal forma que me liste a
quantidade de notas emitidas por dia, o dia em questao e a media de itens
por nota fiscal...

Acho que voce quer informações completamente diferentes.
Veja:

SELECT count(nronf) as notas,dataem,null::int as media from nfc group
by dataem union select null,null,avg(quantidade) from nfi

notas |   dataem    |       media
 -------+-----------------+--------------------
      1 | 2007-05-31 |
      1 | 2007-06-05 |
      3 | 2007-05-21 |
      3 | 2007-05-26 |
         |                  | 6.0000000000000000

Total de notas emitidas por mês e media *total* de itens vendidos

SELECT NRONF,avg(quantidade) from nfi group by nronf;
nronf |         avg
--------+---------------------
     8 | 19.0000000000000000
     7 |  8.0000000000000000
     4 |  3.0000000000000000
     3 |  5.3333333333333333
     2 |  3.5000000000000000
     1 |  3.5000000000000000

Média de itens vendidos por nota.

Abraco!

-Leo
--
Leonardo Cezar
http://www.hostsystems.com.br
http://www.postgresql.org.br
_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a