0% found this document useful (0 votes)
9 views

SQL Exercise 1 - Interview

Uploaded by

Adil Khattab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

SQL Exercise 1 - Interview

Uploaded by

Adil Khattab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL Exercise 1 – Write a Statement

Write an SQL statement that lists school names, student names, and their cities only if the
school and the student are in the same city and the student is not from New York.

Table: school
school_id school_name city
----------- ------------------ ----------
1 Stanford Stanford
2 University of Cali San Francisco
3 Harvard University New York
4 MIT Boston
5 Yale New Haven
Table: student
student_id student_name city school_id
----------- ------------ ---------- -----------
1001 Peter Brebec New York 1
1002 John Goorgy San Francisco 2
2003 Brad Smith New York 3
1004 Fabian Johns Boston 5
1005 Brad Cameron Stanford 1
1006 Geoff Firby Boston 5
1007 Johnny Blue New Haven 2
1008 Johse Brook Miami 2

SQL Exercise 2 – Write a Statement


Write an SQL statement that lists student names, subject names, subject lecturers, and the
max amount of points for all subjects except Computer Science and any subjects with a
max score between 100 and 200.

Table: subject
subject_id subject_name max_score lecturer
---------- ---------- ---------- -----------
11 Math 130 Christena Solem
12 Computer Science 150 Jaime Pille
13 Biology 300 Carrol Denmark
14 Geography 220 Yuette Galang
15 Physics 110 Colton Rather
16 Chemistry 400 Nan Mongeau
Table: student
student_id student_name city subject_id
----------- ------------ ---------- -----------
2001 Thurman Thorn New York 11
2002 Sharda Clemens San Francisco 12
2003 Buck Elkins New York 13
2004 Fabian Johns Boston 15
2005 Brad Cameron Stanford 11
2006 Sofia Roles Boston 16
2007 Rory Pietila New Haven 12

SQL Exercise 3 – Find the Error


What is wrong with this SQL query?
SQL Exercise 4 – Find the Result
Given the following tables …

Table: worker
id name
--- -----------
1 Guillermo Sparks
2 Gene Roberts
3 Ally Jones
4 Bryant Summers
5 Candice Green

Table: departments
id name manager_id
--- ------------- ---------
1 Financial 3
2 Strategy 5
3 IT 1
4 Marketing NULL

SQL Exercise 9 – Write a Complex Query


Write a query that lists courses’ subject names and the number of students taking the
course only if the course has three or more students enrolled.
Table: subject
subject_id subject_name max_score lecturer
---------- ---------- ---------- -----------
11 Math 130 Christena Solem
12 Computer Science 50 Jaime Pille
13 Biology 300 Carrol Denmark
14 Geography 220 Yuette Galang
15 Physics 110 Colton Rather
16 Chemistry 400 Nan Mongeau

Table: student
student_id student_name city subject_id
----------- ------------ ---------- -----------
2001 Thurman Thorn New York 11
2002 Sharda Clemens San Francisco 12
2003 Buck Elkins New York 13
2004 Fabian Johns Boston 15
2005 Brad Cameron Stanford 11
2006 Sofia Roles Boston 16
2007 Rory Pietila New Haven 12
2008 Cicely Weish Tulsa 14
2011 Richard Curtin Boston 11
2012 Kassy Ledger Stanford 11
2013 Henry Ledger Miami 13
2014 Darius Fidzberg San Francisco 12
2015 Darcey Fiorillo Chicago 14

SQL Exercise 2 – Write a Statement


Write an SQL statement that lists student names, subject names, subject lecturers, and the
max amount of points for all subjects except Computer Science and any subjects with a
max score between 100 and 200.

Table: subject
subject_id subject_name max_score lecturer
---------- ---------- ---------- -----------
11 Math 130 Christena Solem
12 Computer Science 150 Jaime Pille
13 Biology 300 Carrol Denmark
14 Geography 220 Yuette Galang
15 Physics 110 Colton Rather
16 Chemistry 400 Nan Mongeau

Table: student
student_id student_name city subject_id
----------- ------------ ---------- -----------
2001 Thurman Thorn New York 11
2002 Sharda Clemens San Francisco 12
2003 Buck Elkins New York 13
2004 Fabian Johns Boston 15
2005 Brad Cameron Stanford 11
2006 Sofia Roles Boston 16
2007 Rory Pietila New Haven 12

You might also like