Skip to content

Commit d925773

Browse files
committed
Upload 165
1 parent 8da863a commit d925773

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-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-164-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-165-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -198,6 +198,7 @@ Because this project necessitated a framework to enable consistent daily practic
198198
| 162 | [Find Products with Valid Serial Numbers](https://leetcode.com/problems/find-products-with-valid-serial-numbers/description/) | [Solution](solutions/162_find_products_with_valid_serial_numbers.md) | LeetCode | Easy | Regex |
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 | |
201+
| 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()` |
201202
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
202203
<!--- cSpell:enable --->
203204

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SQL Everyday \#165
2+
3+
## Daily Hospital Admissions and Discharges Report
4+
5+
Site: Codewars\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
Write a SQL query to generate a daily report that includes the number of admissions, the number of discharges, the net change in patient count for each day, and the cumulative net change over time. [[Full Description](https://www.codewars.com/kata/66b09bedf5ca866d7ffafc8f)]
11+
12+
## Submitted Solution
13+
14+
```sql
15+
-- Submitted Solution
16+
WITH joins AS (
17+
SELECT
18+
TO_CHAR(join_date, 'YYYY-MM-DD') AS j_date
19+
,COUNT(entry_id) AS joins
20+
FROM admissions
21+
GROUP BY j_date
22+
),
23+
exits AS (
24+
SELECT
25+
TO_CHAR(exit_date, 'YYYY-MM-DD') AS e_date
26+
,COUNT(entry_id) AS exits
27+
FROM exits
28+
GROUP BY e_date
29+
),
30+
net AS (
31+
SELECT
32+
COALESCE(j_date, e_date) AS "date"
33+
,COALESCE(joins, 0) AS joins
34+
,COALESCE(exits, 0) AS exits
35+
,CAST(COALESCE(joins, 0) - COALESCE(exits, 0) AS INT) AS net
36+
FROM joins AS j
37+
FULL JOIN exits AS e ON j.j_date = e.e_date
38+
)
39+
SELECT
40+
*
41+
,SUM(net) OVER(ORDER BY "date" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_net
42+
FROM net
43+
;
44+
```
45+
46+
## Site Solution
47+
48+
```sql
49+
-- Codewars Solution
50+
-- TBD
51+
```
52+
53+
## Notes
54+
55+
TBD
56+
57+
## NB
58+
59+
`TO_CHAR()`
60+
61+
Go to [Index](../?tab=readme-ov-file#index)\
62+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)