tiko165 Posted December 2, 2015 at 07:03 PM Report Share #590308 Posted December 2, 2015 at 07:03 PM (edited) Preciso de colocar numa query o ano atual, para fazer contagem de uns dados. Mas como posso escrever o ano automaticamente numa query (Neste caso escrever automaticamente 2015) Edited December 2, 2015 at 07:14 PM by tiko165 Link to comment Share on other sites More sharing options...
vikcch Posted December 2, 2015 at 09:30 PM Report Share #590310 Posted December 2, 2015 at 09:30 PM SELECT COUNT(*) FROM tabela WHERE YEAR(campo) = YEAR(CURDATE()) Link to comment Share on other sites More sharing options...
tiko165 Posted December 2, 2015 at 10:43 PM Author Report Share #590313 Posted December 2, 2015 at 10:43 PM E como posso fazer este SUM, visto que estou a fazer um CASE (Quando é NULL, ou não)?? SELECT id, LEFT(start_circulation,4) AS start_circulation, CASE WHEN LEFT(end_circulation,4) IS NOT NULL THEN LEFT(end_circulation,4) ELSE YEAR(CURDATE()) END AS end_circulatioxn, SUM(end_circulatioxn - start_circulation) AS count_total FROM ce_coins WHERE LEFT(start_circulation,4) != YEAR(CURDATE()) GROUP BY id, start_circulation ORDER BY id ASC Link to comment Share on other sites More sharing options...
vikcch Posted December 3, 2015 at 08:10 AM Report Share #590318 Posted December 3, 2015 at 08:10 AM isso já muito avançado para mim.... mas acho que o que queres usar aí é o DATEDIFF() em vez do SUM() se não conseguires posta aí a tabela com alguns valores e a tabela que queres de retorno... Link to comment Share on other sites More sharing options...
tiko165 Posted December 3, 2015 at 11:34 PM Author Report Share #590348 Posted December 3, 2015 at 11:34 PM Aqui, porque razão as contagens não me estão a dar certas? SELECT valor, count(valor) AS contar_valor, (count(valor) * valor) AS total_valor FROM ce_coins WHERE valor='0.06' Pretendo nesta query: - "valor": obter um determinado valor, - "contar_valor": Quantos valores iguais existem, - "total_valor": Calcular o valor com nrº total Este ultimo resultado não esta a coincidir com o que pretendo. Pois não esta a retornar a multiplicação correcta, dando valores exagerados. Alguem me sabe dizer o porque? 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