fil79 Posted September 18, 2009 at 12:59 PM Report Share #287601 Posted September 18, 2009 at 12:59 PM 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 More sharing options...
ricardoantunes Posted September 18, 2009 at 01:01 PM Report Share #287602 Posted September 18, 2009 at 01:01 PM mete um "having total >0" Link to comment Share on other sites More sharing options...
fil79 Posted September 18, 2009 at 01:08 PM Author Report Share #287604 Posted September 18, 2009 at 01:08 PM 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 More sharing options...
fil79 Posted September 18, 2009 at 01:10 PM Author Report Share #287605 Posted September 18, 2009 at 01:10 PM 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 HAVING total > '0' LIMIT 0 , 30 Obrigadão 😛 MCITP-MCTS-MCP Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now