{"id":3932,"date":"2025-06-06T20:43:44","date_gmt":"2025-06-06T20:43:44","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3932"},"modified":"2025-06-07T09:57:40","modified_gmt":"2025-06-07T09:57:40","slug":"sql-count-sum-avg-min-max","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-count-sum-avg-min-max\/","title":{"rendered":"SQL COUNT \/ SUM \/ AVG \/ MIN \/ MAX"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Aggregate functions perform <strong>calculations on multiple rows<\/strong> and return a single value \u2014 ideal for reports, summaries, and analysis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Syntax &amp; Examples<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- \u2705 COUNT: Total number of rows (non-null values in a column)\nSELECT COUNT(*) FROM employees;\nSELECT COUNT(salary) FROM employees WHERE department = 'IT';\n\n-- \u2705 SUM: Total of a numeric column\nSELECT SUM(salary) FROM employees WHERE department = 'HR';\n\n-- \u2705 AVG: Average of a numeric column\nSELECT AVG(salary) FROM employees;\n\n-- \u2705 MIN \/ MAX: Lowest \/ Highest value\nSELECT MIN(salary) FROM employees;\nSELECT MAX(salary) FROM employees;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 With GROUP BY<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Average salary per department\nSELECT department, AVG(salary)\nFROM employees\nGROUP BY department;\n\n-- Count of employees in each department\nSELECT department, COUNT(*)\nFROM employees\nGROUP BY department;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Function<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>COUNT<\/code><\/td><td>Count rows (or non-null values)<\/td><\/tr><tr><td><code>SUM<\/code><\/td><td>Total of values<\/td><\/tr><tr><td><code>AVG<\/code><\/td><td>Average value<\/td><\/tr><tr><td><code>MIN<\/code><\/td><td>Smallest value<\/td><\/tr><tr><td><code>MAX<\/code><\/td><td>Largest value<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Use these to summarize and analyze your data<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aggregate functions perform calculations on multiple rows and return a single value \u2014 ideal for reports, summaries, and analysis. \ud83d\udd39 Syntax &amp; Examples \ud83d\udd39 With GROUP BY \ud83e\udde0 Quick Recap Function Description COUNT Count rows (or non-null values) SUM Total of values AVG Average value MIN Smallest value MAX Largest value \u2705 Use these to [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3932","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}