Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 130 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Assume that any `_id` columns are incremental, meaning that higher ids always oc

Get the `id` values of the first 5 clients from `district_id` with a value equals to 1.

```sql
select c.client_id
from client c
where district_id = 1
limit 5
```

Expected result:

```shell
Expand All @@ -42,16 +49,31 @@ Expected result:

In the `client` table, get an `id` value of the last client where the `district_id` equals to 72.

```sql
select c.client_id
from client c
where district_id = 72
order by client_id DESC
limit 1
```

Expected result:

```shell
```sql
13576
```

### Query 3

Get the 3 lowest amounts in the `loan` table.

```sql
select l.amount
from loan l
order by amount ASC
limit 3
```

Expected result:

```shell
Expand All @@ -64,6 +86,12 @@ Expected result:

What are the possible values for `status`, ordered alphabetically in ascending order in the `loan` table?

```sql
select l.status
from loan l
group by status
```

Expected result:

```shell
Expand All @@ -77,6 +105,13 @@ D

What is the `loan_id` of the highest payment received in the `loan` table?

```sql
select l.loan_id
from loan l
order by l.payments DESC
limit 1
```

Expected result:

```shell
Expand All @@ -87,6 +122,13 @@ Expected result:

What is the loan `amount` of the lowest 5 `account_id`s in the `loan` table? Show the `account_id` and the corresponding `amount`

```sql
SELECT l.account_id, l.amount
from loan l
order by l.account_id ASC
limit 5
```

Expected result:

```shell
Expand All @@ -102,6 +144,14 @@ Expected result:

What are the `account_id`s with the lowest loan `amount` that have a loan `duration` of 60 in the `loan` table?

```sql
select l.account_id
from loan l
where l.duration = 60
order by l.amount ASC
limit 5
```

Expected result:

```shell
Expand All @@ -118,6 +168,12 @@ What are the unique values of `k_symbol` in the `order` table?

Note: There shouldn't be a table name `order`, since `order` is reserved from the `ORDER BY` clause. You have to use backticks to escape the `order` table name.

```sql
select o.k_symbol
from "order" o
group by o.k_symbol
```

Expected result:

```shell
Expand All @@ -131,6 +187,12 @@ UVER

In the `order` table, what are the `order_id`s of the client with the `account_id` 34?

```sql
select o.order_id
from "order" o
where o.account_id = 34
```

Expected result:

```shell
Expand All @@ -143,6 +205,12 @@ Expected result:

In the `order` table, which `account_id`s were responsible for orders between `order_id` 29540 and `order_id` 29560 (inclusive)?

```sql
select distinct o.account_id
from "order" o
where o.order_id between 29540 and 29560
```

Expected result:

```shell
Expand All @@ -156,6 +224,12 @@ Expected result:

In the `order` table, what are the individual amounts that were sent to (`account_to`) id 30067122?

```sql
select o.amount
from "order" o
where o.account_to = 30067122
```

Expected result:

```shell
Expand All @@ -166,6 +240,14 @@ Expected result:

In the `trans` table, show the `trans_id`, `date`, `type` and `amount` of the 10 first transactions from `account_id` 793 in chronological order, from newest to oldest.

```sql
select t.trans_id, t.date, t.type, t.amount
from trans t
where t.account_id = 793
order by t.date DESC
limit 10
```

Expected result:

```shell
Expand All @@ -185,6 +267,14 @@ Expected result:

In the `client` table, of all districts with a `district_id` lower than 10, how many clients are from each `district_id`? Show the results sorted by the `district_id` in ascending order.

```sql
select c.district_id, count(*)
from client c
where c.district_id < 10
group by c.district_id
order by c.district_id ASC
```

Expected result:

```shell
Expand All @@ -203,6 +293,13 @@ Expected result:

In the `card` table, how many cards exist for each `type`? Rank the result starting with the most frequent `type`.

```sql
select c.type, count(*) as count
from card c
group by type
order by count DESC
```

Expected result:

```shell
Expand All @@ -215,6 +312,14 @@ gold 88

Using the `loan` table, print the top 10 `account_id`s based on the sum of all of their loan amounts.

```sql
select l.account_id, SUM(l.amount) as total_amount
from loan l
group by l.account_id
order by total_amount DESC
limit 10;
```

Expected result:

```shell
Expand All @@ -234,6 +339,14 @@ Expected result:

In the `loan` table, retrieve the number of loans issued for each day, before (excl) 930907, ordered by date in descending order.

```sql
select l.date, count(*)
from loan l
where l.date < 930907
group by date
order by l.date DESC
```

Expected result:

```
Expand All @@ -248,6 +361,14 @@ Expected result:

In the `loan` table, for each day in December 1997, count the number of loans issued for each unique loan duration, ordered by date and duration, both in ascending order. You can ignore days without any loans in your output.

```sql
select l.date, l.duration, COUNT(*) as loan_count
from loan l
where l.date >= 971201 AND l.date <= 971231
group by l.date, l.duration
order by l.date ASC, l.duration ASC;
```

Expected result:

```shell
Expand Down Expand Up @@ -277,6 +398,14 @@ Expected result:

In the `trans` table, for `account_id` 396, sum the amount of transactions for each type (`VYDAJ` = Outgoing, `PRIJEM` = Incoming). Your output should have the `account_id`, the `type` and the sum of amount, named as `total_amount`. Sort alphabetically by type.

```sql
select t.account_id, t.type, SUM(t.amount) AS total_amount
from trans t
where t.account_id = 396
group by t.account_id, t.type
order by t.type ASC;
```

Expected result:

```shell
Expand Down