12. What are the SQL aggregate functions? 13. How do you avoid including duplicate values in a query's results? 14. What is a subquery?
Need help with this
![CRITICAL
THINKING
Single-Table Queries
12. What are the SQL aggregate functions?
13. How do you avoid including duplicate values in a query's results?
14. What is a subquery?
15. How do you group data in an SQL query?
16. When grouping data in a query, how do you restrict the output to only those groups satisfy-
ing some condition?
17. How do you find rows in which a particular column contains a null value?
18. Use the Internet to research the SQL [charlist] wildcard that is available in Oracle and SQL
Server. Using the information you find, complete the following SQL command to find all cit-
ies that begin with the letters "C" or "G."
SELECT CUSTOMER_NAME, CITY
FROM CUSTOMER
WHERE CITY LIKE
Be sure to cite the URL(s) that provided the information.
129](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F69033de8-7a68-4d6e-a6ec-ed8456ab7e76%2F56d26433-5c3d-48b7-9d1e-bdd97ee3b5b7%2Fg6g071u_processed.png&w=3840&q=75)


What are the SQL aggregate functions?
=> SQL (Structured Query Language) provides a set of aggregate functions that allow you to perform calculations on sets of rows in a database table.
=> These aggregate functions summarize and return a single value from a group of multiple rows.
=> Aggregate functions are often used in conjunction with the GROUP BY
clause to perform calculations on groups of rows based on a specific column or columns. Here are some common SQL aggregate functions:
COUNT():
- Calculates the number of rows in a group.
- Example:
SELECT COUNT(*) FROM orders;
SUM():
- Calculates the sum of values in a numeric column.
- Example:
SELECT SUM(price) FROM products;
AVG():
- Calculates the average (mean) value of a numeric column.
- Example:
SELECT AVG(salary) FROM employees;
MIN():
- Retrieves the minimum value from a column.
- Example:
SELECT MIN(age) FROM customers;
MAX():
- Retrieves the maximum value from a column.
- Example:
SELECT MAX(score) FROM students;
GROUP_CONCAT() (MySQL-specific):
- Concatenates the values of a column into a single string, optionally separated by a delimiter.
- Example (MySQL):
SELECT GROUP_CONCAT(name ORDER BY score DESC SEPARATOR ', ') FROM students;
STRING_AGG() (SQL Server-specific):
- Concatenates the values of a column into a single string, optionally separated by a delimiter.
- Example (SQL Server):
SELECT STRING_AGG(product_name, ', ') FROM order_details;
Variance (VAR) and Standard Deviation (STDDEV) (Database-specific):
- Variance and standard deviation are aggregate functions used to measure the dispersion or spread of data.
- Example (PostgreSQL):
SELECT VARIANCE(sales_amount) FROM monthly_sales;
- Example (Oracle):
SELECT STDDEV(price) FROM products;
FIRST() and LAST() (Database-specific):
- These functions retrieve the first or last value in an ordered set.
- Example (Oracle):
SELECT FIRST_NAME, LAST_NAME FROM employees ORDER BY hire_date;
Aggregate Functions with DISTINCT:
- You can use the
DISTINCT
keyword with aggregate functions to apply them to unique values in a column. - Example:
SELECT COUNT(DISTINCT category_id) FROM products;
- You can use the
Aggregate Functions with GROUP BY:
- Aggregate functions are often used in combination with the
GROUP BY
clause to calculate summary values for groups of rows based on one or more columns. - Example:
SELECT department, AVG(salary) FROM employees GROUP BY department;
- Aggregate functions are often used in combination with the
Step by step
Solved in 3 steps









