True or false: The AVG function returns an average of all rows from a select column including any NULL values.
False. The NULLs are not considered .
True or false: The SUM function is used to add column totals.
False. The SUM function is used to return a total for a group of rows.
True or false: The COUNT(*) function counts all rows in a table.
True.
Will the following SELECT statements work? If not, what will fix the statements?
SELECT COUNT * FROM EMPLOYEE_PAY_TBL;
SELECT COUNT(EMPLOYEE_ID), SALARY FROM EMPLOYEE_PAY_TBL;
SELECT MIN(BONUS), MAX(SALARY) FROM EMPLOYEE_PAY_TBL WHERE SALARY > 20000;
This statement will not work because the left and right parentheses are missing around the asterisk. The correct syntax is
SELECT COUNT(*) FROM EMPLOYEE_PAY_TBL;
Yes, this statement will work.
Use EMPLOYEE_PAY_TBL to construct SQL statements to solve the following exercises:
What is the average salary?
What is the maximum bonus?
What are the total salaries?
What is the minimum pay rate?
How many rows are in the table?
The average salary is $30,000.00. The SQL statement to return the data is
SELECT AVG(SALARY) FROM EMPLOYEE_PAY_TBL;
The maximum bonus is $3000.00. The SQL statement to return the data is
SELECT MAX(BONUS) FROM EMPLOYEE_PAY_TBL;
What is the total of all the salaries?
The sum of all the salaries is $60,000.00. The SQL statement to return the data is
SELECT SUM(SALARY) FROM EMPLOYEE_PAY_TBL;
The minimum pay rate is $11.00 an hour. The SQL statement to return the data is
SELECT MIN(PAY_RATE) FROM EMPLOYEE_PAY_TBL;
What is the total rows in the table?
The total row count of the table is six. The SQL statement to return the data is
How many employees do we have whose last names begin with a G?
SELECT COUNT(*) FROM EMPLOYEE_TBL WHERE LAST_NAME LIKE 'G%';
If every product cost $10.00, what would be the total dollar amount for all orders?
SELECT SUM(QTY) * 10 FROM ORDERS_TBL;