lesson 1
1. a.T b. F c. T d.T e.F
2.a.SELECT manager_id,avg(salary)
from employees
having avg(salary)<16000
group by manager_id
b. SELECT cd_number, COUNT(title)
FROM d_cds
WHERE cd_number < 93
group by cd_number
c.SELECT ID, MAX(ID), artist AS "Artist"
FROM d_songs
WHERE duration IN('3 min', '6 min', '10 min')
HAVING ID < 50
GROUP by ID;
d.SELECT loc_type, rental_fee AS "Fee"
FROM d_venues
WHERE id <100
ORDER BY 2;
3.SELECT MAX(DISTINCT(song_id))
FROM d_track_listings
where track IN ( 1, 2, 3);
4.?
5.a.F b.F c.F
lesson 2
F_____1. The CONCAT character function combines two or more character values into one character string.
T_____2. The SYSDATE function returns the Oracle Server date and time.
T_____3. The RPAD character function returns a right-justified value with a string of characters replicated to fill a specified number of character positions.
T_____4. The ROUND number function will round 469.89 to 470 if the decimal place value is omitted.
F_____5. The SUBSTR character function returns a portion of a string beginning at the start of a string to a specified number of characters.
T_____6. DESC will order alphabetical data from Z to A.
T_____7. The column name in a SELECT statement is an example of a SELECTION.
F_____8. You cannot use a column alias in the WHERE clause.
F_____9. To specify an alias in the SELECT clause for retired employee, use 'Retired Employee.'
T_____10. Aliases always appear in UPPERCASE, unless enclosed within proper quote marks.
F_____11. If any column value in an arithmetic expression is NULL, the result defaults to 0.
T_____12. Null values are treated as zero when using SUM functions.
F_____13. In arithmetic expressions, multiply and divide are evaluated after addition and substraction.
T_____14. By default, column headings are returned in UPPERCASE.
T_____15. SQL statements are not case-sensitive, unless indicated.
T_____16. SQL statements can be entered on one or more lines.
T_____17. SQL keywords can be abbreviated using single quotes.
T_____18. Columns are displayed in the order in which they appear in the WHERE clause.
T_____19. Column aliases that are more than one word require the AS prefix.
T_____20. In the SELECT clause, if an expression is not a column name or a column alias, it is a literal value.
T_____21. Number and date values must be enclosed in single quotes.
T_____22. The keyword DISTINCT will affect all of the columns in the statement: SELECT DISTINCT(employee_id, department_id,department_name)
T_____23. HTML DB is a type of application.
T_____24. VARCHAR2 describes variable-length character values.
F_____25. To restrict the rows returned from a query, use the SELECT clause.
F_____26. The comparison operator IN is used to match any of a list of items.
F_____27. Using WHERE employee_id = NULL returns all employees where do not have an employee ID.
F_____28. BETWEEN 250 AND 350 will return 101 values.
T_____29. LIKE '_ _ e%' could return 'Fred.'
T_____30. To return SA_MAN, use LIKE ' SA /_%' ESCAPE ' \ '
T_____31. Logical operators are evaluated in the AND, OR, NOT order.
T_____32. WHERE e.last_name LIKE 'Sm%' OR d.department_id = 60 AND d.department_name = 'IT' could return anyone from the IT department whose department ID is 60.
T_____33. The rules of precedence would evaluate an expression that contained each of the following in the order: arithmetic, concatenation, NOT, OR
T_____34. The ORDER BY clause comes last in the SELECT statement.
T_____35. In SELECT last_name, first_name, the ORDER BY clause could include department_id.
T_____36. The order of execution of a SELECT statement is: FROM, WHERE, SELECT, ORDER BY
F_____37. ADD_MONTHS(hire_date, 6) will return a number.
F_____38. MONTHS BETWEEN ('05-DEC-89' , '10-JUN-93') will return 4.
T_____39. If April 21st is a MONDAY, then NEXT_DAY('21-APR'-03', 'FRIDAY') will return 25-APR-03.
T_____40. ROUND(SYSDATE, 'YEAR') will return 01-JAN-05 if today is August 23, 2004.
F_____41. All group functions ignore NULL values.
F_____42. SELECT COUNT( last_name, first_name) will return the number of last and first names in the database.
F_____43. If salary values in a column are 5000, null, 4000, 7000, using AVG(salary) will return 4000.
T_____44. AVG(DISTINCT salary) will average only the salaries that are different from each other.
F_____45. NULLIF(salary, 4000) will return 4000 if the employee's salary is 5000.
T____ 46. COALESCE(hire_date, salary, commission_pct) will return salary if the hire date is NULL.
T____ 47. The HAVING clause is used to restrict groups.
T____48. If a GROUP BY clause is used, any column that is in the SELECT clause that is not a group function must be listed in the GROUP BY clause.
F_____49. If a query lists clauses WHERE, GROUP BY, and HAVING, no ORDER BY clause can be used.
T_____50. If a join is needed and you want to use a WHERE clause, choose a JOIN ON or JOIN USING join.
T_____51. COUNT(DISTINCT department_id) will return the number of different department IDs.
F_____52. If a column had 4 NULL employee IDs and 250 defined IDs, COUNT will return 254.
lesson 5
1.select title, artist
from d_songs
where type_code=(select type_code
from d_songs
where title='Im Going to Miss My Teacher')
2.select employee_id,last_name,salary
from employees
where salary<(select max(salary)
from employees
where job_id='ST_CLERK')
3.select event_id,song_id
from d_play_list_items
where event_id=(select event_id
from d_play_list_items
where song_id=45)
4.select id, name
from d_events
where cost>(select cost
from d_events
where id=100)
5.select cd_number,title
from d_cds
where cd_number=(select cd_number
from d_cds
where title='Party Music for All Occasions')
6.select code,description
from d_themes
where code=(select code
from d_themes
where description='Tropical')
7.select id,last_name,salary
from f_staffs
where salary>(select salary
from f_staffs
where id=12)
8.select id,last_name,staff_type
from f_staffs
where staff_type<>(select staff_type
from f_staffs
where first_name='Bob' and last_name='Miller')
9.select id,last_name,staff_type,salary
from f_staffs
where salary<(select salary
from f_staffs
where staff_type='Cook')
10.select id,theme_code
from d_events
where theme_code=(select theme_code
from d_events
where id=100)
11.select department_id,department_name
from departments
where department_id=(select department_id
from departments
where department_name='IT')
12.select department_id,department_name
from departments
where location_id=(select location_id
from locations
where city='Seattle')
13.select department_id,min(salary)
from employees
group by department_id
having min(salary)>(select min(salary)
from employees
where department_id<>50)
14.B