W3. SQL Avg Flashcards

1
Q

Q: What does the SQL AVG() function do?

A

A: It returns the average value of a numeric column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Write a query to find the average price in the “Price” column of the “Products” table.

A
SELECT AVG(Price) 
FROM Products;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: Do AVG() calculations include NULL values?

A

A: No, NULL values are ignored in AVG() calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What is the syntax for using AVG() with a condition?

A

SELECT AVG(column_name)
FROM table_name
WHERE condition;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: Write a query to find the average price of products in category 1.

A
SELECT AVG(Price) 
FROM Products 
WHERE CategoryID = 1;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How can you give a descriptive name to the result column of AVG()?

A

A: Use the AS keyword to set an alias, e.g., AS [average price].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: Write a query to find the average price in the “Products” table and label it as “average price.”

A
SELECT AVG(Price) AS [average price] 
FROM Products;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: How do you list all records with a value higher than the average?

A

A: Use a subquery with AVG(), e.g., WHERE Price > (SELECT AVG(Price) FROM Products).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: Write a query to return all products with a price higher than the average price.

A
SELECT * FROM Products 
WHERE Price > (SELECT AVG(Price) FROM Products);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: How do you use AVG() with GROUP BY to find averages for each group?

A

A: Combine AVG() with GROUP BY, e.g., GROUP BY CategoryID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: Write a query to find the average price for each category in the “Products” table.

A
SELECT AVG(Price) AS AveragePrice, CategoryID 
FROM Products 
GROUP BY CategoryID;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly