mirror of
https://github.com/robindhole/fundamentals.git
synced 2025-03-16 23:10:06 +00:00
100 lines
1.5 KiB
Markdown
100 lines
1.5 KiB
Markdown
![]() |
# Queries
|
||
|
|
||
|
## 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
|
||
|
|
||
|
```
|
||
|
|
||
|
## Built-in Functions
|
||
|
1. Get the average IQ of all the students rounded to the nearest integer.
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
2. Find all batches whose name is longer than 10 characters.
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
|
||
|
3. Find all batches whose name's first 10 characters contains the string `sher`
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
|
||
|
4. Get all batches that have started on a Sunday
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
|
||
|
5. Get all batches that have been running for more than 10 years
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
6. Print the name and the instructor's id for each batch. If no instructor is assigned, print `NO INSTRUCTOR`.
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
|
||
|
7. Print the name and IQ of each student. If the IQ of the student is less than 100, print `LOW IQ` instead.
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
|
||
|
8. For each student print the name and their IQ category.
|
||
|
|
||
|
| IQ | Category |
|
||
|
| --------- | -------- |
|
||
|
| < 100 | LOW IQ |
|
||
|
| 100 - 150 | MEDIUM |
|
||
|
| > 150 | HIGH |
|
||
|
|
||
|
```sql
|
||
|
|
||
|
```
|
||
|
|