Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2017
    Posts
    2

    Unanswered: Problem with query on sql server

    Hello i have an error on this query, how can "group by" colum by codart and sum only the column Quantita:

    Click image for larger version. 

Name:	Domanda 1.png 
Views:	4 
Size:	168.5 KB 
ID:	17264


    the query is this:


    SELECT Articolo.CodArt,Articolo.Prezzo,DistintaSemplice.Q uantita,round((DistintaSemplice.Quantita*Articolo. Prezzo),2) as Totale
    FROM [Fatture].[dbo].[SottoCapitolo]
    inner join Fatture.dbo.Distinta
    on Distinta.IdDistinta=SottoCapitolo.Codice
    inner join Fatture.dbo.DistintaSemplice
    on DistintaSemplice.IdDistinta=Distinta.IdDistinta
    inner join Fatture.dbo.Articolo
    on Articolo.IdArticolo=DistintaSemplice.IdArticolo

    where SottoCapitolo.Tipo='Distinta'

    order by CodArt

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,862
    Provided Answers: 17
    Given your sample data, this should do it:
    Code:
    SELECT Articolo.CodArt,
    	Articolo.Prezzo,
    	sum(DistintaSemplice.Quantita),
    	round((sum(DistintaSemplice.Quantita) * Articolo.Prezzo), 2) as Totale
    FROM [Fatture].[dbo].[SottoCapitolo] inner join 
    	Fatture.dbo.Distinta on Distinta.IdDistinta = SottoCapitolo.Codice inner join 
    	Fatture.dbo.DistintaSemplice on DistintaSemplice.IdDistinta = Distinta.IdDistinta inner join 
    	Fatture.dbo.Articolo on Articolo.IdArticolo=DistintaSemplice.IdArticolo
    where SottoCapitolo.Tipo='Distinta
    group by Articolo.CodArt, Articolo.Prezzo
    order by CodArt
    This will break out the Quantite by Prezzo, so if you have items sold at multiple prices, you will get one row per Prezzo.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •