shizzzzzzzz Posted October 7, 2021 at 04:36 PM Report Share #624032 Posted October 7, 2021 at 04:36 PM Boa tarde, estou em volta de um query em Mysql e estou apenas a retornar os valores no total como por exemplo: id | ipaddress | created 1 | 1.1.1.1 | 2021-10-07 2 | 2.2.2.2 | 2021-10-07 3 | 2.2.2.2 | 2021-10-07 4 | 6.6.6.6 | 2021-10-07 5 | 2.2.2.2 |2021-10-07 A minha query é a seguinte: SELECT COUNT(ipaddress) AS total FROM visitors_log GROUP BY DATE(created) ORDER BY created DESC O meu objectivo era não contar os ipaddress repetidos como por exemplo: created | total 2021-10-07 | 3 > numero de ipaddress unicos Link to comment Share on other sites More sharing options...
thoga31 Posted October 7, 2021 at 05:08 PM Report Share #624033 Posted October 7, 2021 at 05:08 PM SELECT Count(ipaddress) AS total FROM (SELECT DISTINCT ipaddress FROM visitors_log GROUP BY DATE(created) ORDER BY created DESC) Penso que assim deverá funcionar, com a keyword DISTINCT. Cumprimentos. Knowledge is free! Link to comment Share on other sites More sharing options...
shizzzzzzzz Posted October 7, 2021 at 05:11 PM Author Report Share #624034 Posted October 7, 2021 at 05:11 PM (edited) 5 minutos atrás, thoga31 disse: SELECT Count(ipaddress) AS total FROM (SELECT DISTINCT ipaddress FROM visitors_log GROUP BY DATE(created) ORDER BY created DESC) Penso que assim deverá funcionar, com a keyword DISTINCT. Cumprimentos. Obtive um erro https://prnt.sc/1v6os74 Edited October 7, 2021 at 05:13 PM by shizzzzzzzz Link to comment Share on other sites More sharing options...
thoga31 Posted October 7, 2021 at 05:19 PM Report Share #624035 Posted October 7, 2021 at 05:19 PM Falha minha, é preciso indicar um alias para a segunda query: SELECT Count(ip) AS total FROM (SELECT DISTINCT ipaddress FROM visitors_log GROUP BY DATE(created) ORDER BY created DESC) ip Passei num syntax checker e deu válido desta forma. Verifica se corre bem assim 🙂 Knowledge is free! Link to comment Share on other sites More sharing options...
shizzzzzzzz Posted October 7, 2021 at 05:21 PM Author Report Share #624036 Posted October 7, 2021 at 05:21 PM 1 minuto atrás, thoga31 disse: Falha minha, é preciso indicar um alias para a segunda query: SELECT Count(ip) AS total FROM (SELECT DISTINCT ipaddress FROM visitors_log GROUP BY DATE(created) ORDER BY created DESC) ip Passei num syntax checker e deu válido desta forma. Verifica se corre bem assim 🙂 Agora deu mas agora não aparece o numero de visitantes unicos no dia X como antes.. Link to comment Share on other sites More sharing options...
shizzzzzzzz Posted October 7, 2021 at 05:24 PM Author Report Share #624037 Posted October 7, 2021 at 05:24 PM (edited) https://prnt.sc/1v6pytk desta maneira aparece todos os users que visitaram a pagina no dia X. Só queria que o numero 19 fosse por exemplo 16 (ou seja, 3 das linhas foram inseridas pelo mesmo IP) Com a tua query deu este retorno: https://prnt.sc/1v6qb7b Edited October 7, 2021 at 05:26 PM by shizzzzzzzz Link to comment Share on other sites More sharing options...
shizzzzzzzz Posted October 8, 2021 at 01:08 PM Author Report Share #624044 Posted October 8, 2021 at 01:08 PM UPDATE: Cheguei um "pouco" mais longe com a query que realizei.. Consegui separar os ipaddress repetidos para so serem mostrados 1x. Mas agora precisava mesmo de contar as datas iguais. Query atual: SELECT DISTINCT ipaddress, DATE_FORMAT(created, '%d-%m-%Y') AS created FROM visitors_log GROUP BY created ORDER BY DATE(created) DESC; Output: https://prnt.sc/1vavxrp Estou já há dois dias à volta disto 😪 será que alguém me consegue ajudar em relacao a isto? Link to comment Share on other sites More sharing options...
Solution Ivo Vicente Posted October 8, 2021 at 01:08 PM Solution Report Share #624045 Posted October 8, 2021 at 01:08 PM Viva, Com recurso ao DISTINCT dentro do COUNT deve resolver SELECT COUNT( DISTINCT ipaddress) AS total FROM access GROUP BY DATE(date) ORDER BY date DESC 1 Report Feito é melhor que perfeito Link to comment Share on other sites More sharing options...
shizzzzzzzz Posted October 8, 2021 at 01:15 PM Author Report Share #624046 Posted October 8, 2021 at 01:15 PM 4 minutos atrás, Ivo Vicente disse: Viva, Com recurso ao DISTINCT dentro do COUNT deve resolver SELECT COUNT( DISTINCT ipaddress) AS total FROM access GROUP BY DATE(date) ORDER BY date DESC Viva, não sei como te agradecer. Acabas-te de me salvar 😅 porque vou precisar de usar isto novamente no futuro! Obrigado a sério ! Link to comment Share on other sites More sharing options...
Ivo Vicente Posted October 8, 2021 at 06:41 PM Report Share #624049 Posted October 8, 2021 at 06:41 PM Ainda bem que resolveu é para isso que este projeto existe. Keep on coding Feito é melhor que perfeito 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