Uploaded by Kyle McSheffery

SQL sample exam

advertisement
Microsoft Access
Q1
SELECT job_id, job_desc
FROM jobs
WHERE job_id >= 2 and job_id <= 8
Q2
SELECT au_id, au_fname, au_lname
FROM authors
WHERE au_fname = 'Heather' and au_lname LIKE 'M%'
Q3
SELECT pub_name, country AS ‘Test’, state AS 'State',
CASE WHEN state = 'NY'
THEN 'New York'
WHEN state='CA'
THEN 'California'
WHEN state='TX'
THEN 'Texas'
ELSE 'Unknown'
END AS 'State Name'
FROM publishers
WHERE country = 'USA'
Q4
SELECT emp_id, job_id, job_lvl
FROM employee
WHERE job_id IN (
SELECT job_id
FROM employee
GROUP BY job_id
HAVING COUNT(job_id) > 1)
and job_id > 3
and job_lvl IN (
SELECT job_lvl
FROM employee
GROUP BY job_lvl
HAVING job_lvl = AVG(job_lvl)
)
and job_lvl IN (
SELECT job_lvl
FROM employee
GROUP BY job_lvl
HAVING job_lvl = MAX(job_lvl)
)
Q5
SELECT emp_id, job_id, job_lvl
FROM employee
WHERE job_id IN (
SELECT job_id
FROM employee
GROUP BY job_id
HAVING COUNT(job_id) >= 3)
and job_id > 3
and job_lvl IN (
SELECT job_lvl
FROM employee
GROUP BY job_lvl
HAVING job_lvl = AVG(job_lvl)
)
and job_lvl IN (
SELECT job_lvl
FROM employee
GROUP BY job_lvl
HAVING job_lvl = MAX(job_lvl)
)
Q6
SELECT fname, lname, employee.job_id, job_desc
FROM employee JOIN jobs ON employee.job_id = jobs.job_id
WHERE job_desc = 'Managing Editor'
Q7
SELECT job_desc, COUNT(job_desc)
FROM employee JOIN jobs ON employee.job_id = jobs.job_id
GROUP BY job_desc
Q8
SELECT title_id, type, price
FROM titles
WHERE type = 'trad_cook' or type = 'mod_cook'
ORDER BY type
COMPUTE SUM(price) BY type
Concatenate two names:
SELECT au_id, au_fname + ' ' + au_lname AS 'Full Name'
FROM authors
LIKE
‘M%’
‘M_ ’
‘M[CF] ’
‘M[^CF]’
Indexes
(Beginning with M)
(M with one character after)
(MC, MD, ME or MF)
(M followed by any char that isn’t C, D, E or F)
The CREATE INDEX statement is used to create indexes in tables. Indexes allow the
database application to find data fast; without reading the whole table.
Download