group table values DISTINCT

0

I have the following table:

ENVIO  ORDEN  LOTE
00011    1     6666
00011    2     6666
00012    3     7777
00012    4     7777
00012    5     8888
00013    6     9999

I need to get from that table, the following:

ENVIO   CTDORDEN  LOTE
00011     2        6666
00012     2        7777
00012     1        8888
00013     1        9999

I have to get all the different batches, and count how many orders there are in each batch and each shipment. I try to make a SELECT DISTINCT but I do not give with the formula .... thanks for the help.

    
asked by panki 29.11.2017 в 19:41
source

1 answer

2

You need a GROUP BY + COUNT instead of DISTINCT :

select envio, count(*) as ctdorden, lote
  from tabla
 group by envio, lote
 order by envio, lote
    
answered by 29.11.2017 в 19:44