├── .github └── workflows │ └── branch_split.yml ├── .gitignore ├── .learn ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── env └── requirements.txt └── index.ipynb /.github/workflows/branch_split.yml: -------------------------------------------------------------------------------- 1 | name: Curriculum Solution Branch Splitter 2 | 3 | on: 4 | push: 5 | branches: curriculum 6 | paths: index.ipynb 7 | workflow_dispatch: 8 | 9 | jobs: 10 | Test_remote_action: 11 | uses: learn-co-curriculum/dsc-github-actions-files/.github/workflows/branch_split.yml@v2.0.0 12 | secrets: inherit 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.ipynb_checkpoints 3 | *.pytest_cache 4 | *.pyc 5 | *__pycache__ 6 | -------------------------------------------------------------------------------- /.learn: -------------------------------------------------------------------------------- 1 | tags: 2 | - jupyter 3 | - python 4 | 5 | languages: python 6 | 7 | jupyter_notebook: true 8 | 9 | resources: 0 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Learn.co Curriculum 2 | 3 | We're really exited that you're about to contribute to the [open 4 | curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). 5 | If this is your first time contributing, please continue reading to learn how 6 | to make the most meaningful and useful impact possible. 7 | 8 | ## Raising an Issue to Encourage a Contribution 9 | 10 | If you notice a problem with the curriculum that you believe needs improvement 11 | but you're unable to make the change yourself, you should raise a Github issue 12 | containing a clear description of the problem. Include relevant snippets of 13 | the content and/or screenshots if applicable. Curriculum owners regularly review 14 | issue lists and your issue will be prioritized and addressed as appropriate. 15 | 16 | ## Submitting a Pull Request to Suggest an Improvement 17 | 18 | If you see an opportunity for improvement and can make the change yourself go 19 | ahead and use a typical git workflow to make it happen: 20 | 21 | * Fork this curriculum repository 22 | * Make the change on your fork, with descriptive commits in the standard format 23 | * Open a Pull Request against this repo 24 | 25 | A curriculum owner will review your change and approve or comment on it in due 26 | course. 27 | 28 | # Why Contribute? 29 | 30 | Curriculum on Learn is publicly and freely available under Learn's 31 | [Educational Content License](https://learn.co/content-license). By 32 | embracing an open-source contribution model, our goal is for the curriculum 33 | on Learn to become, in time, the best educational content the world has 34 | ever seen. 35 | 36 | We need help from the community of Learners to maintain and improve the 37 | educational content. Everything from fixing typos, to correcting 38 | out-dated information, to improving exposition, to adding better examples, 39 | to fixing tests—all contributions to making the curriculum more effective are 40 | welcome. 41 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Learn.co Educational Content License 2 | 3 | Copyright (c) 2018 Flatiron School, Inc 4 | 5 | The Flatiron School, Inc. owns this Educational Content. However, the Flatiron 6 | School supports the development and availability of educational materials in 7 | the public domain. Therefore, the Flatiron School grants Users of the Flatiron 8 | Educational Content set forth in this repository certain rights to reuse, build 9 | upon and share such Educational Content subject to the terms of the Educational 10 | Content License set forth [here](http://learn.co/content-license) 11 | (http://learn.co/content-license). You must read carefully the terms and 12 | conditions contained in the Educational Content License as such terms govern 13 | access to and use of the Educational Content. 14 | 15 | Flatiron School is willing to allow you access to and use of the Educational 16 | Content only on the condition that you accept all of the terms and conditions 17 | contained in the Educational Content License set forth 18 | [here](http://learn.co/content-license) (http://learn.co/content-license). By 19 | accessing and/or using the Educational Content, you are agreeing to all of the 20 | terms and conditions contained in the Educational Content License. If you do 21 | not agree to any or all of the terms of the Educational Content License, you 22 | are prohibited from accessing, reviewing or using in any way the Educational 23 | Content. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # SQL Interview Questions - Lab 3 | 4 | ## Introduction 5 | 6 | In this lab, we'll test our SQL skills against some real-world interview questions from major companies! 7 | 8 | ## Objectives 9 | 10 | You will be able to: 11 | 12 | * Write SQL queries to filter and order results 13 | * Decide and perform whichever type of join is best for retrieving desired data 14 | * Write subqueries to decompose complex queries 15 | 16 | ## Getting Started 17 | 18 | In this lab, we'll see four different interview questions that test your SQL knowledge. We didn't write these questions -- instead, we found them out in the real-world. These are questions that have been used in the past by major technology companies such as Facebook, Amazon, and Twitter. Our goal here isn't to memorize the questions or anything like that -- after all, it's extremely unlikely that these questions are still in use, now that they've become publicly available on the interwebs. Instead, our goal is to treat these questions as if they are the real thing, and give us some insight into the types of questions we'll need to be able to answer in order pass an interview involving SQL. 19 | 20 | If these questions seem hard to you, don't sweat it, they're supposed to be tough! These are meant to help you identify any areas of knowledge where you still need to grow! Use these questions as a way to see where your SQL knowledge is strong, and where it's a bit weak. Then, go study and **practice** in the areas where you still need work! 21 | 22 | ### A Note on Answering These Questions 23 | 24 | Since these are interview questions, they'll almost always be posed as hypotheticals. This means that you won't have a real database to work with and test your code on. This also means that there are multiple different solutions to any given problem listed here. Be sure to doublecheck the code you write for bugs and errors. It's much harder to write bug-free code when you aren't able to test it against a database! 25 | 26 | If these questions seem hard, that's normal. These are real questions that have been reported to online forums from job seekers at major companies. Obviously, it's unlikely that they're still in use at these companies, but they still represent a great way for us to test our skills against the kinds of questions we can expect to be asked in an interview! 27 | 28 | ## Question 1 29 | 30 | From Facebook: 31 | 32 | Assume we have a table of employee information, which includes salary information. Write a query to find the names and salaries of the top 5 highest paid employees, in descending order. 33 | 34 | 35 | ```python 36 | # Your code here 37 | ``` 38 | 39 | ## Question 2 40 | 41 | From Amazon: 42 | 43 | Assume we have two SQL tables: `authors` and `books`. The authors table has a few million rows, and looks like this: 44 | 45 | | author_name | book_name | 46 | |:-----------:|:---------:| 47 | | author_1 | book_1 | 48 | | author_1 | book_2 | 49 | | author_2 | book_3 | 50 | | author_2 | book_4 | 51 | | author_2 | book_5 | 52 | | author_3 | book_6 | 53 | 54 | The books dataset also has a few million rows, and looks like this: 55 | 56 | | book_name | copies_sold | 57 | |:---------:|:-----------:| 58 | | book_1 | 10000 | 59 | | book_2 | 2575 | 60 | | book_3 | 60000 | 61 | | book_4 | 98000 | 62 | | book_5 | 5250 | 63 | | book_6 | 19775 | 64 | 65 | Write an SQL query that shows the top 3 authors who sold the most total books. 66 | 67 | 68 | ```python 69 | # Your code here 70 | ``` 71 | 72 | ## Question 3 73 | 74 | From Amazon: 75 | 76 | Assume you have two tables, `customers` and `orders`. Write a SQL query to select all customers who purchased at least 2 items on two separate days. 77 | 78 | 79 | ```python 80 | # Your code here 81 | ``` 82 | 83 | ## Question 4 84 | 85 | From Twitter: 86 | 87 | A company uses 2 data tables, `Employee` and `Department`, to store data about its employees and departments. 88 | 89 | Table Name: Employee 90 | Attributes: 91 | ID Integer, 92 | NAME String, 93 | SALARY Integer, 94 | DEPT_ID Integer 95 | 96 | Table Name: Department 97 | Attributes: 98 | DEPT_ID Integer, 99 | NAME String, 100 | LOCATION String 101 | 102 | Write a query to print the respective Department Name and number of employees for all departments in the Department table (even unstaffed ones). 103 | 104 | Sort your result in descending order of employees per department; if two or more departments have the same number of employees, then sort those departments alphabetically by Department Name. 105 | 106 | 107 | ```python 108 | # Your code here 109 | ``` 110 | 111 | ## Summary 112 | 113 | In this lab, we tested our knowledge of SQL queries against some real-world interview questions! 114 | -------------------------------------------------------------------------------- /env/requirements.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /index.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# SQL Interview Questions - Lab\n", 8 | "\n", 9 | "## Introduction\n", 10 | "\n", 11 | "In this lab, we'll test our SQL skills against some real-world interview questions from major companies!\n", 12 | "\n", 13 | "## Objectives\n", 14 | "\n", 15 | "You will be able to:\n", 16 | "\n", 17 | "* Write SQL queries to filter and order results\n", 18 | "* Decide and perform whichever type of join is best for retrieving desired data\n", 19 | "* Write subqueries to decompose complex queries\n", 20 | "\n", 21 | "## Getting Started\n", 22 | "\n", 23 | "In this lab, we'll see four different interview questions that test your SQL knowledge. We didn't write these questions -- instead, we found them out in the real-world. These are questions that have been used in the past by major technology companies such as Facebook, Amazon, and Twitter. Our goal here isn't to memorize the questions or anything like that -- after all, it's extremely unlikely that these questions are still in use, now that they've become publicly available on the interwebs. Instead, our goal is to treat these questions as if they are the real thing, and give us some insight into the types of questions we'll need to be able to answer in order pass an interview involving SQL. \n", 24 | "\n", 25 | "\n", 26 | "### A Note on Answering These Questions\n", 27 | "\n", 28 | "Since these are interview questions, they'll almost always be posed as hypotheticals. This means that you won't have a real database to work with and test your code on. This also means that there are multiple different solutions to any given problem listed here. Be sure to doublecheck the code you write for bugs and errors. It's much harder to write bug-free code when you aren't able to test it against a database!\n", 29 | "\n", 30 | "If these questions seem hard, that's normal. These are real questions that have been reported to online forums from job seekers at major companies. Obviously, it's unlikely that they're still in use at these companies, but they still represent a great way for us to test our skills against the kinds of questions we can expect to be asked in an interview!\n", 31 | "\n", 32 | "## Question 1\n", 33 | "\n", 34 | "From Facebook:\n", 35 | "\n", 36 | "Assume we have a table of employee information, which includes salary information. Write a query to find the names and salaries of the top 5 highest paid employees, in descending order." 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "# Your code here" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Question 2\n", 53 | "\n", 54 | "From Amazon:\n", 55 | "\n", 56 | "Assume we have two SQL tables: `authors` and `books`. The authors table has a few million rows, and looks like this: \n", 57 | "\n", 58 | "| author_name | book_name |\n", 59 | "|:-----------:|:---------:|\n", 60 | "| author_1 | book_1 |\n", 61 | "| author_1 | book_2 |\n", 62 | "| author_2 | book_3 |\n", 63 | "| author_2 | book_4 |\n", 64 | "| author_2 | book_5 |\n", 65 | "| author_3 | book_6 |\n", 66 | "\n", 67 | "The books dataset also has a few million rows, and looks like this:\n", 68 | "\n", 69 | "| book_name | copies_sold |\n", 70 | "|:---------:|:-----------:|\n", 71 | "| book_1 | 10000 |\n", 72 | "| book_2 | 2575 |\n", 73 | "| book_3 | 60000 |\n", 74 | "| book_4 | 98000 |\n", 75 | "| book_5 | 5250 |\n", 76 | "| book_6 | 19775 |\n", 77 | "\n", 78 | "Write an SQL query that shows the top 3 authors who sold the most total books. " 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "# Your code here" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "## Question 3\n", 95 | "\n", 96 | "From Amazon:\n", 97 | "\n", 98 | "Assume you have two tables, `customers` and `orders`. Write a SQL query to select all customers who purchased at least 2 items on two separate days. " 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "# Your code here" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "## Question 4\n", 115 | "\n", 116 | "From Twitter:\n", 117 | "\n", 118 | "A company uses 2 data tables, `Employee` and `Department`, to store data about its employees and departments. \n", 119 | "\n", 120 | "Table Name: Employee \n", 121 | "Attributes: \n", 122 | "ID Integer, \n", 123 | "NAME String, \n", 124 | "SALARY Integer, \n", 125 | "DEPT_ID Integer \n", 126 | "\n", 127 | "Table Name: Department \n", 128 | "Attributes: \n", 129 | "DEPT_ID Integer, \n", 130 | "NAME String, \n", 131 | "LOCATION String \n", 132 | "\n", 133 | "Write a query to print the respective Department Name and number of employees for all departments in the Department table (even unstaffed ones). \n", 134 | "\n", 135 | "Sort your result in descending order of employees per department; if two or more departments have the same number of employees, then sort those departments alphabetically by Department Name." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "# Your code here" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "## Summary\n", 152 | "\n", 153 | "In this lab, we tested our knowledge of SQL queries against some real-world interview questions!" 154 | ] 155 | } 156 | ], 157 | "metadata": { 158 | "kernelspec": { 159 | "display_name": "Python 3 (ipykernel)", 160 | "language": "python", 161 | "name": "python3" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.9.7" 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 2 178 | } 179 | --------------------------------------------------------------------------------