Skip to content

Commit 3996ecb

Browse files
committed
Upload 166
1 parent d925773 commit 3996ecb

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- markdownlint-disable MD041 -->
22
[![eevveerryyddaayy release](https://img.shields.io/badge/eevveerryyddaayy-v1.3.0-blue.svg)](https://github.com/ggeerraarrdd/eevveerryyddaayy/)
3-
[![Solved](https://img.shields.io/badge/solved-165-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-166-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -199,6 +199,7 @@ Because this project necessitated a framework to enable consistent daily practic
199199
| 163 | [DNA Pattern Recognition](https://leetcode.com/problems/dna-pattern-recognition/description/) | [Solution](solutions/163_dna_pattern_recognition_.md) | LeetCode | Easy | |
200200
| 164 | [Even or Odd](https://www.codewars.com/kata/53da3dbb4a5168369a0000fe/sql) | [Solution](solutions/164_even_or_odd.md) | Codewars | Easy | |
201201
| 165 | [Daily Hospital Admissions and Discharges Report](https://www.codewars.com/kata/66b09bedf5ca866d7ffafc8f) | [Solution](solutions/165_daily_hospital_admissions_and_discharges_report.md) | Codewars | Medium | `TO_CHAR()` |
202+
| 166 | [Films selection with a twist](https://www.codewars.com/kata/644424f8d7bab510f1375d20) | [Solution](solutions/166_films_selection_with_a_twist.md) | Codewars | Medium | `PERCENTILE_DISC` |
202203
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
203204
<!--- cSpell:enable --->
204205

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SQL Everyday \#166
2+
3+
## Films selection with a twist
4+
5+
Site: Codewars\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
For this task we need to get film_id, film title and length from the `film` table in the DVD rental database, but with a twist: we need to exclude films with a length between the minimum length of R-rated films and the median length of `PG-13` rated films. This means that the selected films will be either strictly shorter than the shortest R-rated film or strictly longer than of median length `PG-13` rated film [[Full Description](https://www.codewars.com/kata/644424f8d7bab510f1375d20)]
11+
12+
## Submitted Solution
13+
14+
```sql
15+
-- Submitted Solution
16+
WITH min_len AS (
17+
SELECT
18+
MIN(length) AS min_length
19+
FROM film
20+
WHERE rating = 'R'
21+
),
22+
median_len AS (
23+
SELECT
24+
PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY length) AS median_length
25+
FROM film
26+
WHERE rating = 'PG-13'
27+
)
28+
SELECT
29+
film_id
30+
,title
31+
,length
32+
FROM film
33+
WHERE (length < (SELECT min_length FROM min_len)) OR
34+
(length > (SELECT median_length FROM median_len))
35+
ORDER BY length ASC, title ASC, film_id ASC
36+
;
37+
```
38+
39+
## Site Solution
40+
41+
```sql
42+
-- Codewars Solution
43+
-- TBD
44+
```
45+
46+
## Notes
47+
48+
TBD
49+
50+
## NB
51+
52+
`PERCENTILE_DISC`
53+
54+
Go to [Index](../?tab=readme-ov-file#index)\
55+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)