SQL To Count If Greater Than 1

Asked

Viewed 1,839 times

-1

My problem is this:

inserir a descrição da imagem aqui

I have to make a condition if the SEQ_VENDA has more than 001 NUMERO, it bring the SELECT data. And if you only have 1 NUMBER for SEQ_VENDA do not bring in SQL

  • What do you mean as referent? and "if SEQ_VENDA has more than 001 NUMERO". Could you explain better?

  • The number is a straight sequence? and the Seq_sale is the sequence of the sale, if the sale has only 1 item, it is not to bring anything, but if the sale has 2 items, the NUMBER will be 001 and 002 and then yes, bring the data.

1 answer

3

returns a row and how many times it occurs (SQL Para Contar Se for Maior Que 1)

SELECT *,
       count(*) AS c
FROM ITENS_VENDA
GROUP BY SEQ_VENDA
HAVING c > 1
ORDER BY c DESC

If you want the complete lines

select * from ITENS_VENDA where SEQ_VENDA in (
    select SEQ_VENDA from ITENS_VENDA
    group by SEQ_VENDA having count(*) > 1
)

Table example

tabela

Upshot

inserir a descrição da imagem aqui

Browser other questions tagged

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