fundamentals/database/notes/09-subqueries-views-worksheet.md

58 lines
938 B
Markdown
Raw Normal View History

2022-10-06 14:56:52 +01:00
# Sub-queries and views worksheet
## Sub-queries
1. Get all the students whose IQ is greater than the average IQ.
```sql
```
2. Get all the students whose IQ is greater than the highest IQ of the batch_id `2` students.
```sql
```
3. Get all the students whose IQ is greater than `all` the IQs of the batch_id `2` students.
```sql
```
4. Find all the students who are in batches that start with the word `Jedi` (Without JOIN)
```sql
```
5. Find all the students whose IQ is greater than the average IQ of their batch.
```sql
```
6. Get all the instructors that have at least one batch (Without using joins)
```sql
```
7. Print all the names, batch ID and average IQ of the batch for each student
```sql
```
## Views
1. Create a view that shows the students and their batches.
```sql
```
2. Create a view that shows the students and their batches, but only for batches that start with the word `Jedi`.
```sql
```