Summarizing data Flashcards
What are the aggregate functions in sql?
MAX, MIN, AVG, SUM, COUNT
What is this query returning?
SELECT MAX(invoice\_total) FROM invoices
the largest invoice total on the invoices table
What is this sql query returning?
the max, min, and avg values as highest, lowest, average of the invoice total on the invoices table
True or False
Aggregate functions can be placed on non-numeric columns as well?
True like a string date
In this query, payment date is referring to what?
the latest payment date
In this query the SUM line is returning what?
summing the invoice_total for the column
In this query the COUNT line is returning what?
the total number of invoices on the table
True or False
Aggregate functions will operate on NULL values?
False
NULL values will be ignored
COUNT(*) returns what?
ALL records, NULL or not
What is the order of operations on this line of code?
SUM(invoice_total * 1.1) AS total
parenthesis first
each row of invoice_total will be multiplied by 1.1 then SUM will be applied.
True or False
Because of the WHERE clause each of the agg functions will be calculated on every row on the invoices table
False
Only those matching the WHERE clause, filtering the number of records being returned
If you want to COUNT unique values (like cleint_id) what statement must also be used?
DISTINCT
Query this result
same SELECT statments with three UNION statements altering the date range in the BETWEEN clause
How many rows are being returned by these multiple SELECT, UNION statements?
3 rows are being queried here.
What is the issue with this query?
the total_sales haven’t been calculated before GROUP BY, use the HAVING statement