Select by selecting the attendant below the call media

Asked

Viewed 36 times

2

Good morning,

Estos trying to make a select to select only the attendants who have the number of calls below the media.

It seems simple, but I’m not succeeding, I’ve tried many ways...

Do not have to count the number of calls in the WHERE put something like "Count(*) < $media"

Thank you.

$media = '40';

SELECT a.adminID
    from os
    JOIN cadastroCliente cc ON cc.cadastroClienteID = os.idcliente
    JOIN administrador a ON a.adminID = os.idusuario
    WHERE os.idusuario = a.adminID
    AND os.status = '1'
    AND os.respondido = '0'
ORDER BY RAND()
LIMIT 1
  • Why not do the count first, and give a Return $Row[count]; and in the next SQL do a new query with Count..

1 answer

3


You’ll have to use having for this, here is an example:

SELECT count(a.adminID), a.adminID
    from os
    JOIN cadastroCliente cc ON cc.cadastroClienteID = os.idcliente
    JOIN administrador a ON a.adminID = os.idusuario
    WHERE os.idusuario = a.adminID
    AND os.status = '1'
    AND os.respondido = '0'
ORDER BY RAND()
LIMIT 1

group by adminID
having count(a.adminID) < 40

Browser other questions tagged

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