Exercise 1
Count all rows in prodotti.
Expected row count: 1
SQL and databases · Lesson
Guided SQL review on real food data, with hints and no JOINs.
Explore real Open Food Facts data in three independent tables, with no JOINs.
Source and license: Open Food Facts — Open Database License (ODbL) 1.0.
Experiment freely: Reset reloads the original food dataset.
COUNT(*) counts rows, COUNT(column) excludes NULL. AVG, MIN, MAX and SUM ignore NULL. ROUND rounds averages.
SELECT ROUND(AVG(zuccheri),2) AS media FROM cereali;
GROUP BY groups brands, categories or Nutri-Score and calculates each aggregate per group.
SELECT categoria, COUNT(*) AS totale FROM prodotti GROUP BY categoria ORDER BY totale DESC LIMIT 10;
WHERE filters products before grouping; HAVING filters groups afterwards. Requiring at least five observations helps avoid misleading tiny groups.
SELECT categoria, ROUND(AVG(zuccheri),2) AS media FROM prodotti WHERE zuccheri IS NOT NULL GROUP BY categoria HAVING COUNT(zuccheri) >= 5 ORDER BY media DESC LIMIT 10;
Write a query for each task. Run it here or in DB Browser; check columns, rows and conditions.
Count all rows in prodotti.
Expected row count: 1
Count drinks with a known sugar value.
Expected row count: 1
Find average sugar in cereals rounded to two decimals.
Expected row count: 1
Find the minimum and maximum calories among drinks.
Expected row count: 1
Rank the ten most common product categories.
Expected row count: 10
Count cereals for each known Nutri-Score grade.
Expected row count: 5
Show the top ten brands with at least five products.
Expected row count: 10
Find ten highest-average-sugar categories with at least five known values.
Expected row count: 10
Which drink categories have at least ten products?
Expected row count: 1
Find ten cereal brands with the highest average calories and at least three available observations.
Expected row count: 10
Choose «Check exercise» to verify your result. If you get stuck, use «Help me» for gradual hints without seeing the full solution immediately.
ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.