Re:SQLite Release 3.25.0 adds support for window functions
by blattimwind on Wednesday August 15, 2018 @09:33AM
(#17765878)
Design queries iteratively.
Having an understanding of relational algebra (not the symbols, but the concept; math is always about the concept) generally helps a lot as well; it's the reason why compsci database lectures often start with relational algebra.
> We would like to find the total weight of cats grouped by age. But only return those groups with a total weight larger than 12.
The total weight of cats grouped by age.
SELECT sum(weight), age
FROM cats
GROUP BY age
But only return those groups with a total weight larger than 12.
SELECT sum(weight), age
FROM cats
GROUP BY age
HAVING sum(weight) > 12
Ordered by age.
SELECT sum(weight), age
FROM cats
GROUP BY age
HAVING sum(weight) > 12
ORDER BY age
The total weight column should be called total_weight.
SELECT sum(weight) AS total_weight, age
FROM cats
GROUP BY age
HAVING sum(weight) > 12
ORDER BY age
Having an understanding of relational algebra (not the symbols, but the concept; math is always about the concept) generally helps a lot as well; it's the reason why compsci database lectures often start with relational algebra.
> We would like to find the total weight of cats grouped by age. But only return those groups with a total weight larger than 12.
The total weight of cats grouped by age.
But only return those groups with a total weight larger than 12. Ordered by age. The total weight column should be called total_weight.