mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-03-17 05:29:58 +00:00
58 lines
938 B
Markdown
58 lines
938 B
Markdown
# 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
|
|
|
|
``` |