Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.50 KB | None | 0 0
  1. select top 20
  2.     ld.Artigo
  3.     ,count(ld.Artigo)
  4.     ,sum(ld.TotalIliquido)
  5. from
  6.     dbo.CabecDoc        as cd
  7. inner join dbo.Clientes as c
  8.     on c.Cliente=cd.Entidade
  9. inner join
  10.     dbo.LinhasDoc       as ld
  11.         on ld.IdCabecDoc = cd.Id
  12. inner join
  13.     dbo.DocumentosVenda as dv
  14.         on dv.Documento = cd.TipoDoc
  15. inner join
  16.     dbo.Artigo          as a
  17.         on a.Artigo = ld.Artigo
  18. inner join dbo.Seccoes as s
  19.     on s.Seccao=c.CDU_Seccao
  20. where
  21.     dv.TipoDocumento >= 4
  22.     and cd.TipoEntidade='C'
  23. group by ld.Artigo
  24. order by count(ld.Artigo) desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement