SQL_Exam
SQL_Exam
Let’s say you have two SQL tables: authors and books.
The authors dataset has 1M+ rows; here’s the first six rows:
author_name book_name
author_1 book_1
author_1 book_2
author_2 book_3
author_2 book_4
author_2 book_5
author_3 book_6
… …
The books dataset also has 1M+ rows and here’s the first six:
book_name sold_copies
book_1 1000
book_2 1500
book_3 34000
book_4 29000
book_5 40000
book_6 4400
… …
Create an SQL query that shows the TOP 3 authors who sold the most books in
total!
Question #2
You work for a startup that makes an online presentation software. You have an event log
that records every time a user inserted an image into a presentation. (One user can insert
multiple images.) The event_log SQL table looks like this:
user_id event_date_time
7494212 1535308430
7494212 1535308433
1475185 1535308444
6946725 1535308475
6946725 1535308476
6946725 1535308477
… …
You have two SQL tables! The first one is called employees and it contains the employee
names, the unique employee ids and the department names of a company. Sample:
department_name employee_id employee_name
… … …
The second one is named salaries. It holds the same employee names and the same
employee ids – and the salaries for each employee. Sample:
salary employee_id employee_name
… … …
The company has 546 employees, so both tables have 546 rows.
Print every department where the average salary per employee is lower than $500!