-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL SCRIPT
74 lines (34 loc) · 1.71 KB
/
SQL SCRIPT
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
select ut.[USER_ID], max(usr.login) login, max(usr.email) email, count(ut.task_id) count_complited,
sum(case when start_date >= cast(getdate()-datepart(dd,getdate())+1 as date)
then datediff(hour,start_date, finish_date)/24
else
datediff(hour,cast(getdate()-datepart(dd,getdate())+1 as date), finish_date)/24
end) total_time,
avg(case when start_date >= cast(getdate()-datepart(dd,getdate())+1 as date)
then datediff(hour,start_date, finish_date)/24
else
datediff(hour,cast(getdate()-datepart(dd,getdate())+1 as date), finish_date)/24
end) avg_time,
count(distinct ut.project_name) project_count,
sum(reward_rub) total_reward,
STRING_AGG (project_name+':'+ cast(reward_rub as varchar(50))+' руб.','; ')
WITHIN GROUP (ORDER BY project_name) extended_info,
max(background_color) background_color,
(select count(*) from user_task usrt
where usrt.[user_id] = ut.[USER_ID]
and usrt.finish_date is null
and usrt.start_date+(1.0*max(utz.timezone/24)) <getdate()
) current_task_count
from user_task ut, [user] usr,
(select login,timezone, background_color from
(select login,timezone, background_color, creation,
max(creation) over(partition by login) mcd
from user_settings) tt
where creation = mcd) utz
where
usr.id = ut.user_id and
utz.login = ut.user_id and
finish_date+(1.0*timezone/24) >= cast(getdate()-datepart(dd,getdate())+2 as date)
group by ut.[USER_ID]
-- select getdate()-1.1,DATEDIFF(hour,getdate(), getdate())
--cast(getdate()-datepart(dd,getdate())+1 as date) between getdate()-30 and getdate()