mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-09-13 18:32:21 +00:00
Finishes aggregate questions.
This commit is contained in:
80
database/notes/06-sql-joins-aggregation-worksheet.md
Normal file
80
database/notes/06-sql-joins-aggregation-worksheet.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Queries
|
||||
|
||||
## Joins
|
||||
|
||||
1. Get all batch names along with their instructor names.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
2. Get all students along with their batch names if present else `NULL`.
|
||||
|
||||
```sql
|
||||
```
|
||||
3. Get all students along with their batch names. Also, fetch all the batches which have no students.
|
||||
|
||||
```sql
|
||||
```
|
||||
4. Get all the combinations of batches and instructors.
|
||||
|
||||
```sql
|
||||
```
|
||||
5. Get all students with their instructors. If a student has no instructor, then show `NULL` for the instructor's name.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
## Aggregation
|
||||
1. Get the maximum IQ in all students (Try without aggregation first).
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
2. Get the maximum IQ in all students (With aggregation).
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
3. Get the oldest batch from the batches table.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
4. Fetch the number of batches that start with the word `Jedi`.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
5. Get the average IQ of all students (Without using `AVG`)
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
6. Get the average IQ of students in all batches.
|
||||
|
||||
```sql
|
||||
```
|
||||
7. Find the average IQ of students in each batch.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
8. Find the total number of students in each batch.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
9. Get the total number of batches taught by each instructor.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
10. Find the average IQ of students in batches with batch ID `1` and `2`.
|
||||
|
||||
```sql
|
||||
```
|
||||
|
||||
11. Find count of students that are part of batches that have average IQ greater than `120`.
|
||||
|
||||
```sql
|
||||
```
|
Reference in New Issue
Block a user