-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsers.sql
477 lines (371 loc) · 20.3 KB
/
Users.sql
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
use DataWarehouse
go
-- transaction fact for user ratings
create table U_Fact_UserRating
(
[user_id] int,
course_key int,
course_id int,
time_key nvarchar(100),
rating decimal(3, 2),
);
create table U_user_rating_temp
(
[user_id] int,
course_key int,
course_id int,
time_key nvarchar(100),
rating decimal(3, 2)
);
create table U_UsersMart_log
(
log_key INT IDENTITY(1,1) PRIMARY KEY,
number_of_rows int,
time_when Date,
full_time Datetime,
fact_name nvarchar(50),
[action] nvarchar(50)
);
select [user_id],course_id,course_key,time_key,rating from U_Fact_UserRating order by [user_id];
Select * from S_Dim_Date
select * from U_user_rating_temp
CREATE or Alter PROCEDURE U_First_Time_Fill_User_rating_fact @first_day_v Date,@today Date
as
begin
truncate table U_Fact_UserRating;
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
while @today>= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
insert into DataWarehouse.dbo.U_user_rating_temp([user_id],course_id,course_key,time_key,rating)
select staging_area.dbo.UserOnlineCourse.[user_id] ,staging_area.dbo.UserOnlineCourse.course_id ,
(select course_key from DataWarehouse.dbo.S_Dim_Course where DataWarehouse.dbo.S_Dim_Course.course_id = staging_area.dbo.UserOnlineCourse.course_id ),
(select DataWarehouse.dbo.S_Make_TimeKey (staging_area.dbo.UserOnlineCourse.datetime_of_rating)), staging_area.dbo.UserOnlineCourse.rating_num
from staging_area.dbo.UserOnlineCourse
where convert(date,staging_area.dbo.UserOnlineCourse.datetime_of_rating)= @passing;
insert into DataWarehouse.dbo.U_Fact_UserRating([user_id],course_id,course_key,time_key,rating)
select [user_id],course_id,course_key,time_key,rating from DataWarehouse.dbo.U_user_rating_temp;
if (select COUNT(*) from DataWarehouse.dbo.U_user_rating_temp ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from DataWarehouse.dbo.U_user_rating_temp ),@passing,GETDATE(),'U_Fact_UserRating','insert first time');
end
truncate table U_user_rating_temp;
set @passing=dateadd(day,1,@passing);
end
end
end
exec U_First_Time_Fill_User_rating_fact @first_day_v = '2020-12-01', @today='2020-12-15';
select * from U_UsersMart_log;
truncate table U_UsersMart_log;
select * from S_Dim_Course
select * from U_Fact_UserRating
select * from staging_area.dbo.UserOnlineCourse
-- *******************************************************
CREATE or Alter PROCEDURE U_Fill_User_rating_fact @first_day_v Date,@today Date
as
begin
declare @passing Date;
declare @timekey nvarchar(255);
while (@today> @passing)
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @today))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
insert into DataWarehouse.dbo.U_user_rating_temp([user_id],course_id,course_key,time_key,rating)
select staging_area.dbo.UserOnlineCourse.[user_id] ,staging_area.dbo.UserOnlineCourse.course_id ,
(select course_key from DataWarehouse.dbo.S_Dim_Course where DataWarehouse.dbo.S_Dim_Course.course_id = staging_area.dbo.UserOnlineCourse.course_id),
(select DataWarehouse.dbo.S_Make_TimeKey (staging_area.dbo.UserOnlineCourse.datetime_of_rating)) , staging_area.dbo.UserOnlineCourse.rating_num
from staging_area.dbo.UserOnlineCourse
where convert(date,staging_area.dbo.UserOnlineCourse.datetime_of_rating)= @passing;
insert into DataWarehouse.dbo.U_Fact_UserRating([user_id],course_id,course_key,time_key,rating)
select [user_id],course_id,course_key,time_key,rating from DataWarehouse.dbo.U_user_rating_temp;
if (select COUNT(*) from DataWarehouse.dbo.U_user_rating_temp ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from DataWarehouse.dbo.U_user_rating_temp ),convert (date,@passing),GETDATE(),'U_Fact_UserRating','insert');
end
truncate table U_user_rating_temp;
set @passing=dateadd(day,1,@passing);
end
end
end
exec U_Fill_User_rating_fact @first_day_v = '2020-12-16', @today='2020-12-20';
--*******************************************************************************
CREATE or Alter PROCEDURE U_First_Time_Fill_U_Fact_Comments @first_day_v Date,@today Date
as
begin
truncate table U_Fact_Comments;
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
while @today>= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
insert into DataWarehouse.dbo.U_Fact_Comments_Temp([user_id],course_id,course_key,time_key,comment_id,comment_text)
select staging_area.dbo.Comment.[user_id] ,staging_area.dbo.Comment.course_id ,
(select course_key from DataWarehouse.dbo.S_Dim_Course where DataWarehouse.dbo.S_Dim_Course.course_id = staging_area.dbo.Comment.course_id ),
(select DataWarehouse.dbo.S_Make_TimeKey (staging_area.dbo.Comment.datetime_created)), staging_area.dbo.Comment.comment_id, staging_area.dbo.Comment.comment_text
from staging_area.dbo.Comment
where convert(date,staging_area.dbo.Comment.datetime_created)= @passing;
insert into DataWarehouse.dbo. U_Fact_Comments([user_id],course_id,course_key,time_key,comment_id,comment_text)
select [user_id],course_id,course_key,time_key,comment_id,comment_text from DataWarehouse.dbo.U_Fact_Comments_Temp;
if (select COUNT(*) from DataWarehouse.dbo.U_Fact_Comments_Temp ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from DataWarehouse.dbo.U_Fact_Comments_Temp),@passing,GETDATE(),'U_Fact_Comments','insert first time');
end
truncate table U_Fact_Comments_Temp;
set @passing=dateadd(day,1,@passing);
end
end
end
exec U_First_Time_Fill_U_Fact_Comments @first_day_v = '1995-01-01', @today='2020-10-10';
select * from U_Fact_Comments
select * from U_Fact_Comments_Temp
--*************************************************************
CREATE or Alter PROCEDURE U_Fill_U_Fact_Comments @first_day_v Date,@today Date
as
begin
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
while @today>= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
insert into DataWarehouse.dbo.U_Fact_Comments_Temp([user_id],course_id,course_key,time_key,comment_id,comment_text)
select staging_area.dbo.Comment.[user_id] ,staging_area.dbo.Comment.course_id ,
(select course_key from DataWarehouse.dbo.S_Dim_Course where DataWarehouse.dbo.S_Dim_Course.course_id = staging_area.dbo.Comment.course_id ),
(select DataWarehouse.dbo.S_Make_TimeKey (staging_area.dbo.Comment.datetime_created)), staging_area.dbo.Comment.comment_id, staging_area.dbo.Comment.comment_text
from staging_area.dbo.Comment
where convert(date,staging_area.dbo.Comment.datetime_created)= @passing;
insert into DataWarehouse.dbo. U_Fact_Comments([user_id],course_id,course_key,time_key,comment_id,comment_text)
select [user_id],course_id,course_key,time_key,comment_id,comment_text from DataWarehouse.dbo.U_Fact_Comments_Temp;
if (select COUNT(*) from DataWarehouse.dbo.U_Fact_Comments_Temp ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from DataWarehouse.dbo.U_Fact_Comments_Temp),@passing,GETDATE(),'U_Fact_Comments','insert');
end
truncate table U_Fact_Comments_Temp;
set @passing=dateadd(day,1,@passing);
end
end
end
exec U_Fill_U_Fact_Comments @first_day_v = '2020-10-11', @today='2021-01-31';
select * from U_Fact_Comments
select * from U_UsersMart_log;
select * from S_Dim_Date
insert into S_Dim_Date(TimeKey,FullDateAlternateKey,PersianFullDateAlternateKey,DayNumberOfWeek) values('20210131','2021-01-31','1399-11-12',1);
insert into S_Dim_Date(TimeKey,FullDateAlternateKey,PersianFullDateAlternateKey,DayNumberOfWeek) values('20201111','2020-11-11','1399-09-12',1);
--********************************************************************************
CREATE or Alter PROCEDURE U_First_Time_Fill_U_Fact_CommentRating @first_day_v Date,@today Date
as
begin
truncate table U_Fact_CommentRating;
truncate table U_Fact_CommentRating_Temp;
truncate table U_Fact_CommentRating_Temp2;
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
insert into DataWarehouse.dbo.U_Fact_CommentRating_Temp(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,datetime_created,was_it_helpful ,description_WasItHelpful)
select staging_area.dbo.Comment.[user_id] ,staging_area.dbo.CommentVote.voter_user_id,staging_area.dbo.Comment.course_id ,
(select course_key from DataWarehouse.dbo.S_Dim_Course where DataWarehouse.dbo.S_Dim_Course.course_id = staging_area.dbo.Comment.course_id ),
(select DataWarehouse.dbo.S_Make_TimeKey (staging_area.dbo.CommentVote.datetime_created)), staging_area.dbo.CommentVote.comment_id,staging_area.dbo.CommentVote.datetime_created,staging_area.dbo.CommentVote.was_it_helpful,
case
when was_it_helpful = 1 then 'Helpful'
when was_it_helpful = 0 then 'Not Helpful'
end
from staging_area.dbo.Comment inner join staging_area.dbo.CommentVote on staging_area.dbo.Comment.comment_id = staging_area.dbo.CommentVote.comment_id;
while @today >= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
insert into DataWarehouse.dbo.U_Fact_CommentRating_Temp2(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful)
select commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful from DataWarehouse.dbo.U_Fact_CommentRating_Temp
where convert(date,DataWarehouse.dbo.U_Fact_CommentRating_Temp.datetime_created) = @passing;
insert into DataWarehouse.dbo. U_Fact_CommentRating(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful)
select commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful from DataWarehouse.dbo.U_Fact_CommentRating_Temp2;
if (select COUNT(*) from DataWarehouse.dbo.U_Fact_CommentRating_Temp2 ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from DataWarehouse.dbo.U_Fact_CommentRating_Temp2),@passing,GETDATE(),'U_Fact_CommentRating','insert first time');
end
truncate table U_Fact_CommentRating_Temp2;
set @passing=dateadd(day,1,@passing);
end
end
truncate table U_Fact_CommentRating_Temp;
end
exec U_First_Time_Fill_U_Fact_CommentRating @first_day_v = '2020-11-01', @today='2020-11-11';
select * from U_Fact_CommentRating;
delete from U_UsersMart_log where log_key >10
select * from U_UsersMart_log
select * from U_Fact_CommentRating_Temp;
--********************************************************************************
CREATE or Alter PROCEDURE U_Fill_U_Fact_CommentRating @first_day_v Date,@today Date
as
begin
truncate table U_Fact_CommentRating_Temp;
truncate table U_Fact_CommentRating_Temp2;
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
insert into DataWarehouse.dbo.U_Fact_CommentRating_Temp(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,datetime_created,was_it_helpful ,description_WasItHelpful)
select staging_area.dbo.Comment.[user_id] ,staging_area.dbo.CommentVote.voter_user_id,staging_area.dbo.Comment.course_id ,
(select course_key from DataWarehouse.dbo.S_Dim_Course where DataWarehouse.dbo.S_Dim_Course.course_id = staging_area.dbo.Comment.course_id ),
(select DataWarehouse.dbo.S_Make_TimeKey (staging_area.dbo.CommentVote.datetime_created)), staging_area.dbo.CommentVote.comment_id,staging_area.dbo.CommentVote.datetime_created,staging_area.dbo.CommentVote.was_it_helpful,
case
when was_it_helpful = 1 then 'Helpful'
when was_it_helpful = 0 then 'Not Helpful'
end
from staging_area.dbo.Comment inner join staging_area.dbo.CommentVote on staging_area.dbo.Comment.comment_id = staging_area.dbo.CommentVote.comment_id;
while @today >= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
insert into DataWarehouse.dbo.U_Fact_CommentRating_Temp2(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful)
select commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful from DataWarehouse.dbo.U_Fact_CommentRating_Temp
where convert(date,DataWarehouse.dbo.U_Fact_CommentRating_Temp.datetime_created) = @passing;
insert into DataWarehouse.dbo. U_Fact_CommentRating(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful)
select commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful from DataWarehouse.dbo.U_Fact_CommentRating_Temp2;
if (select COUNT(*) from DataWarehouse.dbo.U_Fact_CommentRating_Temp2 ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from DataWarehouse.dbo.U_Fact_CommentRating_Temp2),@passing,GETDATE(),'U_Fact_CommentRating','insert');
end
truncate table U_Fact_CommentRating_Temp2;
set @passing=dateadd(day,1,@passing);
end
end
truncate table U_Fact_CommentRating_Temp;
end
exec U_Fill_U_Fact_CommentRating @first_day_v = '2020-11-12', @today='2021-01-31';
select * from U_Fact_CommentRating where comment_id=24997 and voter_user_id=917;
--truncate table U_Fact_CommentRating;
--**********************************************************************************
CREATE or Alter PROCEDURE U_First_Time_Fill_Fact_InfluentialUsers_Acc @first_day_v Date,@today Date
as
begin
truncate table U_Fact_InfluentialUsers_Acc;
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
while @today>= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
--insert a day from Rating
insert into DataWarehouse.dbo.U_Fact_CommentRating_Temp2(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful)
select commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful
from DataWarehouse.dbo.U_Fact_CommentRating
where (select FullDateAlternateKey from DataWarehouse.dbo.S_Dim_Date where DataWarehouse.dbo.U_Fact_CommentRating.time_key=DataWarehouse.dbo.S_Dim_Date.TimeKey)=@passing;
--add this day to previous days
with t(commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful)
as(
select commenter_user_id,COUNT(commenter_user_id),COUNT(was_it_helpful),COUNT(CASE was_it_helpful When 1 THEN 1 ELSE Null END)
from DataWarehouse.dbo.U_Fact_CommentRating_Temp2
group by commenter_user_id)
insert into U_Fact_InfluentialUsers_Acc_Temp(commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful)
select t.commenter_user_id,ISNULL(0,U_Fact_InfluentialUsers_Acc.sum_of_comments)+t.sum_of_comments
,ISNULL(0,U_Fact_InfluentialUsers_Acc.sum_of_Feedbacks)+t.sum_of_comments,ISNULL(0,U_Fact_InfluentialUsers_Acc.sum_of_WasItHelpful)+t.sum_of_WasItHelpful
from t left join U_Fact_InfluentialUsers_Acc
ON t.commenter_user_id= DataWarehouse.dbo.U_Fact_InfluentialUsers_Acc.commenter_user_id;
insert into U_Fact_InfluentialUsers_Acc(commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful)
select commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful from U_Fact_InfluentialUsers_Acc_Temp;
if (select COUNT(*) from U_Fact_InfluentialUsers_Acc_Temp ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from U_Fact_InfluentialUsers_Acc_Temp),@passing,GETDATE(),'U_Fact_InfluentialUsers_Acc','insert first time');
end
truncate table U_Fact_InfluentialUsers_Acc_Temp;
truncate table DataWarehouse.dbo.U_Fact_CommentRating_Temp2;
set @passing=dateadd(day,1,@passing);
end
end
end
select * from U_Fact_InfluentialUsers_Acc;
exec U_First_Time_Fill_Fact_InfluentialUsers_Acc @first_day_v = '2020-11-01', @today='2020-11-11';
select commenter_user_id,COUNT(commenter_user_id),
COUNT(was_it_helpful) as NumberOfVote,COUNT(CASE was_it_helpful When 1 THEN 1 ELSE Null END)
from DataWarehouse.dbo.U_Fact_CommentRating
group by comment_id,commenter_user_id
order by commenter_user_id
select * from dataWarehouse.dbo.U_UsersMart_log
--****************************************************************
CREATE or Alter PROCEDURE U_First_Fact_InfluentialUsers_Acc @first_day_v Date,@today Date
as
begin
declare @passing Date;
declare @timekey nvarchar(255);
set @passing = @first_day_v;
while @today>= @passing
begin
if (not exists (select * from DataWarehouse.dbo.[S_Dim_Date] where DataWarehouse.dbo.[S_Dim_Date].FullDateAlternateKey = @passing))
begin
set @passing=dateadd(day,1,@passing);
end
else
begin
--insert a day from Rating
insert into DataWarehouse.dbo.U_Fact_CommentRating_Temp2(commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful)
select commenter_user_id,voter_user_id,course_id,course_key,time_key,comment_id,was_it_helpful ,description_WasItHelpful
from DataWarehouse.dbo.U_Fact_CommentRating
where (select FullDateAlternateKey from DataWarehouse.dbo.S_Dim_Date where DataWarehouse.dbo.U_Fact_CommentRating.time_key=DataWarehouse.dbo.S_Dim_Date.TimeKey)=@passing;
--add this day to previous days
with t(commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful)
as(
select commenter_user_id,COUNT(commenter_user_id),COUNT(was_it_helpful),COUNT(CASE was_it_helpful When 1 THEN 1 ELSE Null END)
from DataWarehouse.dbo.U_Fact_CommentRating_Temp2
group by commenter_user_id)
insert into U_Fact_InfluentialUsers_Acc_Temp(commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful)
select t.commenter_user_id,ISNULL(0,U_Fact_InfluentialUsers_Acc.sum_of_comments)+t.sum_of_comments
,ISNULL(0,U_Fact_InfluentialUsers_Acc.sum_of_Feedbacks)+t.sum_of_comments,ISNULL(0,U_Fact_InfluentialUsers_Acc.sum_of_WasItHelpful)+t.sum_of_WasItHelpful
from t left join U_Fact_InfluentialUsers_Acc
ON t.commenter_user_id= DataWarehouse.dbo.U_Fact_InfluentialUsers_Acc.commenter_user_id;
insert into U_Fact_InfluentialUsers_Acc(commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful)
select commenter_user_id,sum_of_comments,sum_of_Feedbacks,sum_of_WasItHelpful from U_Fact_InfluentialUsers_Acc_Temp;
if (select COUNT(*) from U_Fact_InfluentialUsers_Acc_Temp ) > 0
begin
insert into DataWarehouse.dbo.U_UsersMart_log (number_of_rows,time_when ,full_time ,fact_name ,[action] )
values ((select COUNT(*) from U_Fact_InfluentialUsers_Acc_Temp),@passing,GETDATE(),'U_Fact_InfluentialUsers_Acc','insert');
end
truncate table U_Fact_InfluentialUsers_Acc_Temp;
truncate table DataWarehouse.dbo.U_Fact_CommentRating_Temp2;
set @passing=dateadd(day,1,@passing);
end
end
end
exec U_First_Fact_InfluentialUsers_Acc @first_day_v = '2020-11-12', @today='2021-01-31';
select * from U_Fact_InfluentialUsers_Acc