mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-03-15 23:19:56 +00:00
80 lines
1.3 KiB
Markdown
80 lines
1.3 KiB
Markdown
# 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
|
|
``` |