SQLite aggregate query
SQLite databases support common aggregation queries, including the following:
1. COUNT: Calculate the number of rows
Example: Counting the number of records in a table
sqlite
SELECT COUNT(*) FROM table_name;
2. SUM: Calculate the sum of a column
Example: Calculating the Sum of a Column in a Table
sqlite
SELECT SUM(column_name) FROM table_name;
3. AVG: Calculate the average value of a column
Example: Calculate the average value of a column in a table
sqlite
SELECT AVG(column_name) FROM table_name;
4. MAX: Find the maximum value of a certain column
Example: Finding the maximum value of a column in a table
sqlite
SELECT MAX(column_name) FROM table_name;
5. MIN: Find the minimum value of a certain column
Example: Finding the minimum value of a column in a table
sqlite
SELECT MIN(column_name) FROM table_name;
6. GROUP BY: Group the results by a certain column
Example: Grouping results based on the values of a certain column and counting the number of each group
sqlite
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
7. HAVING: Filter based on GROUP BY
Example: Find groups with a column value greater than or equal to 5, and count the number of each group
sqlite
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name HAVING column_name >= 5;
It should be noted that the table structure and sample data may vary depending on specific requirements. The 'tablename' and 'columnname' in the above example need to be replaced with the actual table and column names.