1 Answer
- Newest
- Most votes
- Most comments
0
I hope this is helpful for you.
SELECT
(final - inicial) / final AS variacion,
c.comuna,
inicial,
final
FROM
codigo_comuna_region AS c
INNER JOIN (
SELECT
cod_com,
count(numero_linea) AS inicial,
(
SELECT
count(numero_linea)
FROM
const
WHERE
periodo = '1-2021' AND
cod_com = c1.cod_com
) AS final
FROM
const AS c1
WHERE
periodo = '1-2011'
GROUP BY
cod_com
) AS d ON c.cod_com = d.cod_com
ORDER BY
variacion DESC
LIMIT
10;
answered a year ago
It doesn't work for me, I get a column filled with 0 in variation, and it doesn't order it in DESC by variation because when I run the code a second time it gives me a different result than the first.
my "initial and final column" is not a column from the database, it is a column that I did through a select, because the data of the initial and final column are together in a "period" column
Relevant content
- asked 3 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
The title language seems to be Spanish, so modify it in English so your might get an answer sooner.