Jump to content

Count em mysql


tiko165
 Share

Recommended Posts

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
collectioneuro300px.png
Link to comment
Share on other sites

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?

collectioneuro300px.png
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.