-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.sql
More file actions
61 lines (54 loc) · 1.13 KB
/
provider.sql
File metadata and controls
61 lines (54 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
USE kyruus;
-- Change the table name to providers_visit
ALTER TABLE visit_type
RENAME TO providers_visit;
-- Removing blank values
DELETE FROM providers_visit
WHERE source_system = ''
OR provider_id = ''
OR provider_name = ''
OR provider_npi = ''
OR visit_type_id = ''
OR duration = ''
OR dept_id = ''
OR dept_name = ''
OR appt_date = ''
OR appt_time = '';
-- Preview data
SELECT * FROM providers_visit
LIMIT 10;
-- Sorted for provider_id
SELECT DISTINCT
provider_id,
visit_type,
duration
FROM
providers_visit
ORDER BY provider_id;
-- Unique visit type and duration combinations for each provider
SELECT DISTINCT
provider_id,
provider_name,
visit_type_id,
visit_type,
duration
FROM
providers_visit
WHERE provider_id = 1234;
-- Most frequetnly used durations for each visit type
SELECT
visit_type,
duration
FROM
(
SELECT visit_type,
duration,
row_number() OVER (PARTITION BY visit_type ORDER BY duration_frequency DESC) AS row_num
FROM (SELECT visit_type,
duration,
count(duration) AS duration_frequency
FROM providers_visit
GROUP BY 1, 2
) AS frequency
) AS a
WHERE a.row_num = 1