-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbusiness_days.sql
More file actions
58 lines (37 loc) · 1.71 KB
/
business_days.sql
File metadata and controls
58 lines (37 loc) · 1.71 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
use Practice
-- calculate the number of days to resolve the tickets
-- provide total days, business days and removing public holidays
select *,
DATEDIFF(day,create_date,resolved_date) as total_days_taken,
DATEDIFF(week,create_date,resolved_date) as week_diff,
DATEDIFF(DAY,create_date,resolved_date) - 2*(DATEDIFF(week,create_date,resolved_date)) as business_days,
DATEPART(week,resolved_date) as week_num
from dbo.tickets
with CTE as
(
select t.ticket_id, t.create_date, resolved_date, count(holiday_date) as no_of_holidays from tickets t
left join (select * from holidays where datename(dw,holiday_date) <> 'Saturday')h
on h.holiday_date between t.create_date and t.resolved_date
group by t.ticket_id, t.create_date, resolved_date)
select *,
DATEDIFF(day,create_date,resolved_date) as total_days_taken,
DATEDIFF(DAY,create_date,resolved_date) - 2*(DATEDIFF(week,create_date,resolved_date)) as business_days,
DATEDIFF(DAY,create_date,resolved_date) - 2*(DATEDIFF(week,create_date,resolved_date)) - no_of_holidays as business_days_ex_holidays
from cte
-- get the count the filter count
select value as room_type, count(*) as cnt from dbo.airbnb_searches
cross apply string_split(filter_room_types,',')
group by value
order by cnt desc
with cte_table as
(select count(case when filter_room_types like '%entire home%' then 1 End) as 'entire home',
count(case when filter_room_types like '%private room%' then 1 End) as 'private room',
count(case when filter_room_types like '%shared room%' then 1 End) as 'shared room'
from
airbnb_searches)
Select value, i as count_room_type from cte_table
unpivot
(
i for value in ([entire home],[private room],[shared room])
) as unpivot_table
ORDER By i DESC;