Loading subject…
GROUP BY the function returns one number per group instead of one for the whole table.AVG.SELECT AVG(Quantity) AS AverageQuantity FROM Purchase;SELECT COUNT(ItemID) AS TotalItems FROM Purchase;SELECT MAX(ItemCost) AS HighestCost, MIN(ItemCost) AS LowestCost FROM Item;SELECT SUM(ItemCost) AS TotalCost FROM Item WHERE ArtistID = 105;AS gives the calculated column a readable name, called an alias.SUM(ItemCost).COUNT(*) counts every row that reached it, whatever those rows contain.COUNT(ColumnName) counts only the rows where that column is not NULL.COUNT(DISTINCT ColumnName) counts how many different values appear, so ten purchases of the same item count once.COUNT(DISTINCT CustomerID) is the answer to the question that was actually asked.COUNT(*) ignores NULL values instead of treating them as zero.SUM(ItemCost) returns 1000, and AVG(ItemCost) returns 250 because it divides by four, not by five.GROUP BY ArtistID runs the same calculation once per artist and returns one row each.SELECT ArtistID, SUM(ItemCost) AS TotalSalesFROM ItemGROUP BY ArtistIDHAVING SUM(ItemCost) > 1000ORDER BY TotalSales DESC;SELECT ItemID, COUNT(*) AS PurchaseCount FROM Purchase GROUP BY ItemID ORDER BY PurchaseCount DESC;