Agrupando Valores

Forum sobre SQL.

Moderador: Moderadores

Avatar do usuário
asimoes
Colaborador
Colaborador
Mensagens: 4919
Registrado em: 26 Abr 2007 16:48
Localização: RIO DE JANEIRO-RJ

Agrupando Valores

Mensagem por asimoes »

Estou usando o ADS, ponte para migrar para um SGDB, o que eu faço no oracle algo como, agora com DBF, to gostando:

Código: Selecionar todos

         cQuery := "SELECT APC.CODIGO, APC.NOME, APC.TELEFONE, APC.CLASSE_PG, APC.D_ADMISS, APC.UTI, RES.TOTAL, RES.GUIAS AS GUIAS "   
         cQuery += "FROM "   
         cQuery += "  APC01 APC "
         cQuery += "  INNER JOIN " 
         cQuery += "  ( "
         cQuery += "  SELECT "
         cQuery += "  APA.CODIGO, Sum(APA.VL_GUIA) AS TOTAL, COUNT(APA.CODIGO) AS GUIAS "
         cQuery += "  FROM "
         cQuery += "  APA01 APA "
         cQuery += "  WHERE "
         cQuery += "  APA.D_VENC < ? AND "
         cQuery += "  APA.D_PGTO IS NULL AND "
         cQuery += "  APA.D_VENC IS NOT NULL "
         cQuery += "  GROUP BY "
         cQuery += "  APA.CODIGO "
         cQuery += "  ) RES ON RES.CODIGO = APC.CODIGO "
         cQuery += "WHERE "
         cQuery += "SUBSTRING(APC.CLASSE_PG,1,2) IN (?,?,?,?,?) AND "
         cQuery += "APC.D_DESLIG IS NULL AND "
         cQuery += "APC.D_FALECI IS NULL AND "
         cQuery += "GUIAS >= ? "
         cQuery += "ORDER BY APC.CODIGO"
►Harbour 3.x | Minigui xx-x | HwGui◄
Pense nas possibilidades abstraia as dificuldades.
Não corrigir nossas falhas é o mesmo que cometer novos erros.
A imaginação é mais importante que o conhecimento. (Albert Einstein)
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Agrupando Valores

Mensagem por JoséQuintas »

asimoes escreveu:Estou usando o ADS, ponte para migrar para um SGDB, o que eu faço no oracle algo como, agora com DBF, to gostando:
No tempo que usei não funcionava sub-query.

Muito bom pra quem ainda tem DBF, pra poder já ver resultados mais rápidos, enquanto vai se acostumando com SQL.
E pra aplicativos monstrinhos, pra adiantar a conversão.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder