Doubt with JOINS and GROUP BY in an SQL (Access) query

Asked

Viewed 34 times

1

Thanks for your help. I am not very advanced in SQL and I am facing a difficulty here, is the following:

SELECT tbl_afs_pregao.numaf, 
       tbl_items_pregao.nomeitem, 
       Sum(tbl_items_af.qtd) AS SomaDeQtd, 
       tbl_items_pregao.id_itempregao 
FROM   (tbl_afs_pregao 
        INNER JOIN tbl_items_af 
                ON tbl_afs_pregao.id_af = tbl_items_af.id_af) 
       INNER JOIN tbl_items_pregao 
               ON tbl_items_af.id_itempregao = tbl_items_pregao.id_itempregao 
GROUP  BY tbl_afs_pregao.numaf, 
          tbl_items_pregao.nomeitem, 
          tbl_items_pregao.id_itempregao; 

The result is this: inserir a descrição da imagem aqui

The point is that I wanted to group the results of those items, SUNPATIENS by the sum of the quantity, but not getting it (1 hour almost trying and already gave rs).

I thank you all,

Hug

  • 1

    You’re grouping too by tbl_afs_pregao.numaf and the 2 lines of SUNPATIENS shown have different values for this field (1374/2020 and 1522/2020).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.