etapombas 0 Denunciar post Postado Junho 30, 2011 Galera eu tenho a seguinte tabela CREATE TABLE `points` ( `id` int(10) unsigned NOT NULL auto_increment, `partner_id` int(10) unsigned default NULL, `client_id` int(10) unsigned default NULL, `date` date default NULL, `price` float(10,2) default '0.00', `created` datetime default NULL, `modified` datetime default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3526 DEFAULT CHARSET=latin1; Eu preciso contar quantos pontos distintos de um parceiro o cliente recebeu, seria + / - assim. O Bruno recebeu 5 pontos, destes pontos 3 são do parceiros X e mais 2 pontos do parceiro Y. Só que executando a query abaixo eu recebo 13 registros, quanto na verdade eu queria receber 1 registro indicando a contagem de 13. SELECT client_id, count(partner_id) as total FROM points WHERE client_id IN (40) GROUP BY partner_id Será que consegui explicar? Abs Compartilhar este post Link para o post Compartilhar em outros sites
Motta 645 Denunciar post Postado Julho 1, 2011 SELECT client_id, partner_id , count(client_id) as total FROM points WHERE client_id IN (40) GROUP BY client_id, partner_id SELECT client_id, count(DISTINCT partner_id) as total_partners FROM points WHERE client_id IN (40) GROUP BY client_id Compartilhar este post Link para o post Compartilhar em outros sites
etapombas 0 Denunciar post Postado Julho 1, 2011 SELECT client_id, partner_id , count(client_id) as total FROM points WHERE client_id IN (40) GROUP BY client_id, partner_id SELECT client_id, count(DISTINCT partner_id) as total_partners FROM points WHERE client_id IN (40) GROUP BY client_id Uhuuuuuuuuu funcionou, muitíssimo obrigado Compartilhar este post Link para o post Compartilhar em outros sites