Doubt - Query (Do not bring a particular record)

Asked

Viewed 494 times

0

Good afternoon Galera!

Next, below is a query where it was to bring all the calls that has the description ''Block Client - Delinquent' and with id = 572 (blocked clients), however, this query has some customers with already been unlocked, IE, already have a call with another description. I wanted to know how to bring only the records with locked clients without any calling with unlocking. Below is the query I tried.

SELECT  DISTINCT
*
FROM Tarefa T
WHERE 
T.TarID in(select TarID from Tarefa where T.TarTitulo = 'Bloquear Cliente - Inadimplente' AND T.TarTipID = 572
and T.TarID not in (select TarID from Tarefa where TarTipID = 574 and TarTitulo = 'Desbloqueio Cliente'))
  • What is the customer table/field?

  • The Table is Task only and the client field is client

  • Let me get this straight, your problem is that customers that have already been unlocked are showing up, so is there a date field in this Task table? in that case you just want to run the filter on the last customers calls?

1 answer

2


You can use the clause EXISTS together with the NOT to discover customers who have not called unlocking:

SELECT DISTINCT *
  FROM Tarefa T
 WHERE T.TarTitulo = 'Bloquear Cliente - Inadimplente'
   AND T.TarTipID = 572
   AND NOT EXISTS(SELECT 1
                    FROM Tarefa t2
                   WHERE t2.TarTitulo = 'Desbloqueio Cliente'
                     AND t2.TarTipID = 574
                     AND t2.usuidcliente = t.usuidcliente)
  • my young man. It worked out, man. Very obg!

Browser other questions tagged

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