Currently learning Data Science, here is what I've learnt so far. Pt.3
Hey there! I'm getting used to posting here and really enjoying using this space to post my notes while learning. This time I learned about aggregates and how to structure my SQL queries when using them. Feel free to comment any tips, corrections, or suggestions you might have for me. Thx! ;) Aggregates - Calculations performed on multiple rows of a table. COUNT() - count the number of rows SUM()…
As I continue my journey into Data Science, I've begun exploring aggregates and their role in structuring SQL queries. Aggregates involve calculations on multiple rows within a table.
Functions like COUNT(), SUM(), MAX(), MIN(), and AVG() perform various operations on data. ROUND() handles rounding of values, and conditionals can be added to aggregates. These elements can be combined in a single query, like SELECT aggregate (column_name) FROM table_name WHERE conditional.
To round values, one can employ ROUND(column_name, int_decimal_places) FROM table_name. Stacking aggregates is also possible; for instance, SELECT ROUND(AVG(table_name), int_decimal_places) FROM table_name. To calculate aggregates for specific data characteristics, GROUP BY is used.
GROUP BY groups a result set based on an aggregate function (COUNT(), MIN(), MAX(), SUM(), AVG()), listing the number in each group. It is utilized with aggregate functions and SELECT to arrange identical data into groups. It follows WHERE statements, preceding ORDER BY or LIMIT. Additionally, it can be employed with calculations on a column.
HAVING, on the other hand, limits the results of a query based on individual row values (WHERE) versus an aggregate property (HAVING), which occurs after GROUP BY and before ORDER BY and LIMIT. The SQLite function for creating formatted dates is strftime(format, column), with format options like %Y for year (YYYY), %m for month (01-12), %d for day (1-31), %H for 24-hour clock (00-23), %M for minute (00-59), and %S for seconds (00-59).
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to
This story
This is one outlet's version. Read the fullest account.