Skip to content
Open
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions sql-lt01/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# sql-lt01

Status:

➕ - task description is done
✅ - ready to prod

| Title | Level | XP | Link | Done? |
| ----------------------- | ----- | ------- | ---------------------------------------------------- | ----- |
| fulls-lt | 1 | 100 | [README.md](./fulls-lt/README.md) | ✅ |
| track-info | 1 | 100 | [README.md](./track-info/README.md) | ✅ |
| employee-profile | 1 | 100 | [README.md](./employee-profile/README.md) | ✅ |
| ----------------------- | ----- | ------- | ------------------------------------------------- | ----- |
| long-ones | 2 | 150 | [README.md](./long-ones/README.md) | ✅ |
| track-filter | 2 | 150 | [README.md](./track-filter/README.md) | ✅ |
| name-search | 2 | 150 | [README.md](./name-search/README.md) | ✅ |
| ----------------------- | ----- | ------- | ------------------------------------------------- | ----- |
| genre-stats | 3 | 200 | [README.md](./genre-stats/README.md) | ✅ |
| price-summary | 3 | 200 | [README.md](./price-summary/README.md) | ✅ |
| composer-tracks | 3 | 200 | [README.md](./composer-tracks/README.md) | ✅ |
| ----------------------- | ----- | ------- | ------------------------------------------------- | ----- |
| above-average | 4 | 250 | [README.md](./above-average/README.md) | ✅ |
| genre-max | 4 | 250 | [README.md](./genre-max/README.md) | ✅ |
| popular-composers | 4 | 250 | [README.md](./popular-composers/README.md) | ✅ |
| ----------------------- | ----- | ------- | ------------------------------------------------- | ----- |
| album-info | 5 | 300 | [README.md](./album-info/README.md) | ✅ |
| playlist-genres | 5 | 300 | [README.md](./playlist-genres/README.md) | ✅ |
| ----------------------- | ----- | ------- | ------------------------------------------------- | ----- |
| playlist-stats | 6 | 350 | [README.md](./playlist-stats/README.md) | ✅ |
| artist-sales | 6 | 350 | [README.md](./artist-sales/README.md) | ✅ |
| ----------------------- | ----- | ------- | ------------------------------------------------- | ----- |
| customer-artist | 7 | 400 | [README.md](./customer-artist/README.md) | ✅ |
| premium-ones | 7 | 400 | [README.md](../story07/premium-ones/README.md) | ✅ |
41 changes: 41 additions & 0 deletions sql-lt01/above-average/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# above-average

| Expected file |
| ------------- |
| `above-average.sql` |

Find all tracks that cost more than average price.

Show for each track:
- Track's name as `TrackName`
- Track's price `TrackPrice`
- Genre name as `Genre`

Note:
- Only show tracks with price higher than average price of **ALL** tracks
- Sort the result by track's price in descending order

# Table: `tracks`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `TrackId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(200) | NOT NULL |
| `AlbumId` | INTEGER | FOREIGN KEY REFERENCES `albums(AlbumId)` |
| `MediaTypeId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `media_types(MediaTypeId)` |
| `GenreId` | INTEGER | FOREIGN KEY REFERENCES `genres(GenreId)` |
| `Composer` | NVARCHAR(220) | NULLABLE |
| `Milliseconds` | INTEGER | NOT NULL |
| `Bytes` | INTEGER | NULLABLE |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
```

# Table: `genres`

```
| Column Name | Data Type | Constraints |
|-------------|---------------|----------------------|
| `GenreId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(120) | NULLABLE |
```
52 changes: 52 additions & 0 deletions sql-lt01/album-info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# album-info

| Expected file |
| ------------- |
| `album-info.sql` |

Show information about albums and their artists.

Show:
- Album title as `AlbumTitle`
- Artist name as `Artist`
- Number of tracks as `TrackCount`
- Total price of all tracks as `TotalPrice`, rounded to 2 decimals

Note:
- Include only albums that have at least 5 tracks
- Sort the result by number of tracks in descending order

# Table: `artists`

```
| Column Name | Data Type | Constraints |
|-------------|-------------|----------------------|
| `ArtistId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(120) | NULLABLE |
```

# Table: `albums`

```
| Column Name | Data Type | Constraints |
|-------------|-------------|---------------------------------------|
| `AlbumId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Title` | NVARCHAR(160) | NOT NULL |
| `ArtistId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `artists(ArtistId)` |
```

# Table: `tracks`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `TrackId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(200) | NOT NULL |
| `AlbumId` | INTEGER | FOREIGN KEY REFERENCES `albums(AlbumId)` |
| `MediaTypeId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `media_types(MediaTypeId)` |
| `GenreId` | INTEGER | FOREIGN KEY REFERENCES `genres(GenreId)` |
| `Composer` | NVARCHAR(220) | NULLABLE |
| `Milliseconds` | INTEGER | NOT NULL |
| `Bytes` | INTEGER | NULLABLE |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
```
67 changes: 67 additions & 0 deletions sql-lt01/artist-sales/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# artist-sales

| Expected file |
| ------------- |
| `artist-sales.sql` |

Find sales statistics for each artist.

Note:
- Only include artists with the price of their tracks equal to most expensive track of that track among their albums
- Most expensive track has highest `UnitPrice`
- Only include artists whose total revenue is more than `$50`
- Calculate total revenue as sum of (`UnitPrice` × `Quantity`)
- Sort result by a total revenue in descending order

Show for each artist:
- Artist name as `ArtistName`
- Name as `TopTrack`
- Track price as `TrackPrice`
- Total amount of money spent as `TotalRevenue`, rounded to 2 decimals

# Table: `artists`

```
| Column Name | Data Type | Constraints |
|-------------|-------------|----------------------|
| `ArtistId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(120) | NULLABLE |
```

# Table: `albums`

```
| Column Name | Data Type | Constraints |
|-------------|-------------|---------------------------------------|
| `AlbumId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Title` | NVARCHAR(160) | NOT NULL |
| `ArtistId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `artists(ArtistId)` |
```

# Table: `tracks`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `TrackId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(200) | NOT NULL |
| `AlbumId` | INTEGER | FOREIGN KEY REFERENCES `albums(AlbumId)` |
| `MediaTypeId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `media_types(MediaTypeId)` |
| `GenreId` | INTEGER | FOREIGN KEY REFERENCES `genres(GenreId)` |
| `Composer` | NVARCHAR(220) | NULLABLE |
| `Milliseconds` | INTEGER | NOT NULL |
| `Bytes` | INTEGER | NULLABLE |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
```

# Table: `invoice_items`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `InvoiceLineId`| INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `InvoiceId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `invoices(InvoiceId)` |
| `TrackId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `tracks(TrackId)` |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
| `Quantity` | INTEGER | NOT NULL |
```
34 changes: 34 additions & 0 deletions sql-lt01/composer-tracks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# composer-tracks

| Expected file |
| ------------- |
| `composer-tracks.sql` |

Find composers who wrote more than `10` tracks.

Show:

- Composer's name as it is
- Number of their tracks as `TrackCount`

Note:

- Skip composers that are `NULL`, so the composer `IS NOT NULL`
- Only show composers with more than 10 tracks
- Sort the result by number of tracks in descending order

# Table: `tracks`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `TrackId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(200) | NOT NULL |
| `AlbumId` | INTEGER | FOREIGN KEY REFERENCES `albums(AlbumId)` |
| `MediaTypeId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `media_types(MediaTypeId)` |
| `GenreId` | INTEGER | FOREIGN KEY REFERENCES `genres(GenreId)` |
| `Composer` | NVARCHAR(220) | NULLABLE |
| `Milliseconds` | INTEGER | NOT NULL |
| `Bytes` | INTEGER | NULLABLE |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
```
112 changes: 112 additions & 0 deletions sql-lt01/customer-artist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# customer-artist

| Expected file |
| ------------- |
| `customer-artist.sql` |

Find customers' favorite artists based on purchase history.

For each customer and artist combination (customer and artist ids) calculate:
1. How many of artist's tracks customer bought
2. Total amount spent on this artist's tracks
3. What percentage of customer's total purchases these tracks represent
4. Number of **unique** albums bought from

Then show:
- Customer's full name (first and last names separated by single space) as `Customer`
- Artist name as `ArtistName`
- Number of tracks bought as `TrackCount`
- Total spent on artist as `TotalSpent`, rounded to 2 decimal places
- Percentage of all purchases as `Percentage`, rounded to 1 decimal place
- Number of **unique** albums as `AlbumCount`

Where:
- Only include customers who spent more than `$40` in total
- Only show artists that make up more than `5%` of customer's purchases

Note:
- Calculate total spent as UnitPrice × Quantity from invoice_items
- Sort the result by customer name in ascending order, then by total spent descending order

# Table: `artists`

```
| Column Name | Data Type | Constraints |
|-------------|-------------|----------------------|
| `ArtistId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(120) | NULLABLE |
```

# Table: `albums`

```
| Column Name | Data Type | Constraints |
|-------------|-------------|---------------------------------------|
| `AlbumId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Title` | NVARCHAR(160) | NOT NULL |
| `ArtistId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `artists(ArtistId)` |
```

# Table: `customers`

```
| Column Name | Data Type | Constraints |
|---------------|---------------|---------------------------------------|
| `CustomerId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `FirstName` | NVARCHAR(40) | NOT NULL |
| `LastName` | NVARCHAR(20) | NOT NULL |
| `Company` | NVARCHAR(80) | NULLABLE |
| `Address` | NVARCHAR(70) | NULLABLE |
| `City` | NVARCHAR(40) | NULLABLE |
| `State` | NVARCHAR(40) | NULLABLE |
| `Country` | NVARCHAR(40) | NULLABLE |
| `PostalCode` | NVARCHAR(10) | NULLABLE |
| `Phone` | NVARCHAR(24) | NULLABLE |
| `Fax` | NVARCHAR(24) | NULLABLE |
| `Email` | NVARCHAR(60) | NOT NULL |
| `SupportRepId`| INTEGER | FOREIGN KEY REFERENCES `employees(EmployeeId)` |
```

# Table: `invoices`

```
| Column Name | Data Type | Constraints |
|--------------------|---------------|---------------------------------------|
| `InvoiceId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `CustomerId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `customers(CustomerId)` |
| `InvoiceDate` | DATETIME | NOT NULL |
| `BillingAddress` | NVARCHAR(70) | NULLABLE |
| `BillingCity` | NVARCHAR(40) | NULLABLE |
| `BillingState` | NVARCHAR(40) | NULLABLE |
| `BillingCountry` | NVARCHAR(40) | NULLABLE |
| `BillingPostalCode`| NVARCHAR(10) | NULLABLE |
| `Total` | NUMERIC(10,2) | NOT NULL |
```

# Table: `tracks`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `TrackId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `Name` | NVARCHAR(200) | NOT NULL |
| `AlbumId` | INTEGER | FOREIGN KEY REFERENCES `albums(AlbumId)` |
| `MediaTypeId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `media_types(MediaTypeId)` |
| `GenreId` | INTEGER | FOREIGN KEY REFERENCES `genres(GenreId)` |
| `Composer` | NVARCHAR(220) | NULLABLE |
| `Milliseconds` | INTEGER | NOT NULL |
| `Bytes` | INTEGER | NULLABLE |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
```

# Table: `invoice_items`

```
| Column Name | Data Type | Constraints |
|----------------|---------------|---------------------------------------|
| `InvoiceLineId`| INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `InvoiceId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `invoices(InvoiceId)` |
| `TrackId` | INTEGER | NOT NULL, FOREIGN KEY REFERENCES `tracks(TrackId)` |
| `UnitPrice` | NUMERIC(10,2) | NOT NULL |
| `Quantity` | INTEGER | NOT NULL |
```
35 changes: 35 additions & 0 deletions sql-lt01/employee-profile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# employee-profile

| Expected file |
| ------------------------- |
| `employee-profile.sql` |

Display employee's contact information where show their:

- last name
- email
- country

Sort result by last name in ascending order

# Table: `employees`

```
| Column Name | Data Type | Constraints |
|--------------|-------------|---------------------------------------|
| `EmployeeId` | INTEGER | PRIMARY KEY, AUTOINCREMENT |
| `LastName` | NVARCHAR(20) | NOT NULL |
| `FirstName` | NVARCHAR(20) | NOT NULL |
| `Title` | NVARCHAR(30) | NULLABLE |
| `ReportsTo` | INTEGER | FOREIGN KEY REFERENCES `employees(EmployeeId)` |
| `BirthDate` | DATETIME | NULLABLE |
| `HireDate` | DATETIME | NULLABLE |
| `Address` | NVARCHAR(70) | NULLABLE |
| `City` | NVARCHAR(40) | NULLABLE |
| `State` | NVARCHAR(40) | NULLABLE |
| `Country` | NVARCHAR(40) | NULLABLE |
| `PostalCode` | NVARCHAR(10) | NULLABLE |
| `Phone` | NVARCHAR(24) | NULLABLE |
| `Fax` | NVARCHAR(24) | NULLABLE |
| `Email` | NVARCHAR(60) | NULLABLE |
```
Loading