Jump to content

dúvida SQL


fil79
 Share

Recommended Posts

Boas

tenho esta query para listar clientes e nela faço uma conta onde aparece a subtracção do total de apolices com as apolices anuladas (se for maior que zero tem apólices em vigor):

SELECT cliente.nome, morada1, morada1b, cp1, localidade1, (
Count( apolice.apolice_id ) - SUM( apolice.anulada ) 
) AS total
FROM cliente
INNER JOIN apolice ON ( cliente.cliente_id = apolice.tomador ) 
WHERE activo =1
GROUP BY cliente.cliente_id

basicamente pretendo que sejam apenas listados os clientes que tenham apolices em vigor

ou seja onde o total seja maior que zero, já tentei adicionar essa clausula no WHERE mas dá sempre erro..Desde já agradeço

MCITP-MCTS-MCP

Link to comment
Share on other sites

assim dá erro(#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'having total>'0' GROUP BY cliente.cliente_id LIMIT 0, 30' at line 6):

SELECT cliente.nome, morada1, morada1b, cp1, localidade1, (
Count( apolice.apolice_id ) - SUM( apolice.anulada ) 
) AS total
FROM cliente
INNER JOIN apolice ON ( cliente.cliente_id = apolice.tomador ) 
WHERE activo =1 and having total>0
GROUP BY cliente.cliente_id
LIMIT 0 , 30

MCITP-MCTS-MCP

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.