Код работал нормально. Сегодня утром я вижу, что после того, как автоматизированное задание запустилось, оно заполнило дубликаты. После расследования я обнаружил, что таблицы фактов не содержат дубликатов, а одно из представлений. Как мне удалить дубликаты просмотров? Код как ниже:
SELECT DISTINCT
fact.Incident.Number, fact.Incident.Activity_Due, fact.Incident.Additional_Assignee_List, fact.Incident.Approval_History, fact.Incident.Approval_Set, fact.Incident.Business_Duration, fact.Incident.Business_Service,
fact.Incident.Business_STC, fact.Incident.Calendar_Duration, fact.Incident.Calendar_STC, fact.Incident.Caused_By, fact.Incident.Close_Code, fact.Incident.Close_Notes, fact.Incident.Cmdb_CI AS Hide,
fact.Incident.Comments, fact.Incident.Comments_And_Work_Notes, fact.Incident.Contract, fact.Incident.Contact_Type, fact.Incident.Correlation_Display, fact.Incident.Correlation_ID, fact.Incident.Description,
fact.Incident.Due_Date, fact.Incident.Escalation, fact.Incident.Expected_Start, fact.Incident.Follow_Up, fact.Incident.Group_List, fact.Incident.Impact, fact.Incident.Incident_State, fact.Incident.Knowledge,
fact.Incident.Made_SLA, fact.Incident.Notify, fact.Incident.[Order], fact.Incident.Parent, fact.Incident.Parent_Incident, fact.Incident.Priority, fact.Incident.Problem_ID, fact.Incident.Reassignment_Count,
fact.Incident.Rejection_goto, fact.Incident.Reopen_Count, fact.Incident.RFC, fact.Incident.Service_Offering AS [To hide], fact.Incident.Severity, fact.Incident.Short_Description, fact.Incident.Skills,
fact.Incident.SLA_Due, fact.Incident.State, fact.Incident.Subcategory, fact.Incident.Sys_Class_Name, fact.Incident.Sys_Domain, fact.Incident.Companies, fact.Incident.Sys_ID, fact.Incident.Sys_Mod_Count,
fact.Incident.Time_Worked, fact.Incident.u_Approver, fact.Incident.u_Bomgar, fact.Incident.u_Comments_Updated, fact.Incident.u_Confidential, fact.Incident.u_Escalated_To, fact.Incident.u_Feedback,
fact.Incident.u_First_Category, fact.Incident.u_First_CI, fact.Incident.u_Group_Internal, fact.Incident.u_Has_Attachments, fact.Incident.u_ManagementGroup, fact.Incident.u_Metric_Timeline, fact.Incident.u_Noted,
fact.Incident.u_One_To_One_Training, fact.Incident.u_Prev_Short_Desc, fact.Incident.u_Priority_Changed, fact.Incident.u_Problem_Candidate, fact.Incident.u_Proccess_Sync, fact.Incident.u_Response_Time,
fact.Incident.u_Solution, fact.Incident.u_Type, fact.Incident.u_Update_KB, fact.Incident.u_Vendor, fact.Incident.u_Vendor_Number, fact.Incident.Upon_Approval, fact.Incident.Upon_Reject, fact.Incident.Urgency,
fact.Incident.User_Input, fact.Incident.Variables, fact.Incident.Vendor, fact.Incident.Vendor_Closed_At, fact.Incident.Vendor_Opened_At, fact.Incident.Vendor_Point_of_Contact, fact.Incident.Vendor_Resolved_at,
fact.Incident.Vendor_Ticket, fact.Incident.Watch_List, fact.Incident.Work_End, fact.Incident.Work_Notes, fact.Incident.Work_Notes_List, fact.Incident.Work_Start, fact.Incident.Table_Insert_Date,
fact.Incident.Table_Update_Date, fact.Incident.Link, fact.Incident.[Updated By Email], fact.Incident.[Priority Name], fact.Incident.[Severity Name], fact.Incident.[Urgency Name], fact.Incident.[State Name],
dim.dimDate.Day AS [Closed at Day], dim.dimDate.WeekDayName AS [Closed at Day Name], dim.dimDate.IsWeekend AS [Closed at is weekend], dim.dimDate.Month AS [Closed at month],
dim.dimDate.MonthName AS [Closed at month name], dim.dimDate.Quarter AS [Closed at quarter], dim.dimDate.Year AS [Closed at year], dim.dimDate.MMYYYY AS [Closed at MMYYYY],
dimDate_1.Day AS [Opened at day], dimDate_1.WeekDayName AS [Opened at Day Name], dimDate_1.IsWeekend AS [Opened isweekend], dimDate_1.Month AS [Opened Month],
dimDate_1.MonthName AS [Opened Month Name], dimDate_1.Quarter AS [Opened Quarter], dimDate_1.Year AS [Opened Year], dimDate_1.MMYYYY AS [Opened MMYYYY],
dim.dimLocation.city AS [Location City], dim.dimLocation.country AS [Location Country], dim.dimLocation.state AS [Location State], dim.dimLocation.IsBureau AS [Location IsBureau],
dim.dimLocation.IsNewsroom AS [Location IsNewsroom], dim.dimLocation.contact AS [Location Contact], dim.dimLocation.Location, dimEmployee_2.[Full Name] AS [Caller ID Name],
dimEmployee_2.EmployeeID AS [Caller ID (Employee ID)], dimEmployee_2.[Email Address] AS [Caller ID Email Address], dimEmployee_2.[Job Title] AS [Caller ID Job Title],
dimEmployee_2.Department AS [Caller ID Department], dimEmployee_2.[Mobile Phone] AS [Caller ID Mobile Phone], dimEmployee_2.[Business Phone] AS [[Caller ID]] Business Phone],
dimEmployee_2.Company AS [Caller ID Company], dimDate_2.Date AS [Created On Date], dimDate_2.Day AS [Created On Day], dimDate_2.WeekDayName AS [Created On Day Name],
dimDate_2.IsWeekend AS [Created On IsWeekend], dimDate_2.IsHolidayQatar AS [Created On IsholidayQatar], dimDate_2.Month AS [Created Month], dimDate_2.MonthName AS [Created MonthName],
dimDate_2.Quarter AS [Created Quarter], dimDate_2.Year AS [Created Year], dimDate_2.MMYYYY AS [Created MMYYYY], fact.Incident.Active, dimDate_3.Day AS [Updated Day],
dimDate_3.WeekDayName AS [Updated Day Name], dimDate_3.IsWeekend AS [Updated IsWeekend], dimDate_3.Month AS [Updated Month], dimDate_3.MonthName AS [Updated Month Name],
dimDate_3.Quarter AS [Updated Quarter], dimDate_3.Year AS [Updated Year], dimDate_3.MMYYYY AS [Updated MMYYYY], fact.Incident.Closed_At AS [Closed at Date],
fact.Incident.Opened_at AS [Opened at date], fact.Incident.Sys_Updated_On AS Updated, servicenow.staging_category.u_name AS Category, fact.Incident.u_Category,
servicenow.staging_business_service.name AS Service_Offering, servicenow.staging_configuration_item.name AS CMDB_CI, fact.Incident.Child_Incidents,
dimEmployee_2.[User Primary Group] AS [Caller Primary Group], user_1.name AS [Opened By Full Name], user_1.employee_number AS [Opened By Employee ID], user_1.email AS [Opened By Email Address],
user_1.title AS [Opened By Job Title], user_1.Department AS [Opened By Department], user_1.mobile_phone AS [Opened By Mobile Phone], user_1.Company AS [Opened By Company],
user_1.u_primary_group AS [Opened By Primary Group], fact.[user].name AS [Closed By], fact.[user].email AS [Closed By Email Address], fact.[user].title AS [Closed By Job Title],
fact.[user].Department AS [Closed By Department], fact.[user].Company AS [Closed By Company], fact.[user].mobile_phone AS [Closed By Mobile Phone], fact.[user].phone AS [Closed By Business Phone],
fact.[user].u_primary_group AS [Closed By Primary Group], fact.Incident.[Assignment Group], fact.Incident.[Opened By Email] AS [Assignment Group Manager],
fact.Incident.[Caller ID Email] AS [Assignment Group Email], user_2.u_primary_group AS [Assigned To Primary Group], user_2.employee_number AS [Employee ID(Assigned to)],
fact.Incident.[Assigned to Email] AS [Email Address (Assigned to)], user_2.name AS [Assigned to]
FROM fact.Incident LEFT OUTER JOIN
fact.[user] AS user_2 ON fact.Incident.[Assigned to Email] = user_2.email LEFT OUTER JOIN
fact.[user] ON fact.Incident.[Closed By Email] = fact.[user].email LEFT OUTER JOIN
fact.[user] AS user_1 ON fact.Incident.[Opened By Email] = user_1.email LEFT OUTER JOIN
servicenow.staging_configuration_item ON fact.Incident.Cmdb_CI = servicenow.staging_configuration_item.sys_id LEFT OUTER JOIN
servicenow.staging_business_service ON fact.Incident.Service_Offering = servicenow.staging_business_service.sys_id LEFT OUTER JOIN
servicenow.staging_category ON fact.Incident.u_Category = servicenow.staging_category.sys_id LEFT OUTER JOIN
dim.dimDate ON fact.Incident.[Closed At Datekey] = dim.dimDate.DateKey LEFT OUTER JOIN
dim.dimDate AS dimDate_1 ON fact.Incident.[Opened At Datekey] = dimDate_1.DateKey LEFT OUTER JOIN
dim.dimLocation ON fact.Incident.Location = dim.dimLocation.Location LEFT OUTER JOIN
dim.dimDate AS dimDate_2 ON fact.Incident.[Created Datekey] = dimDate_2.DateKey LEFT OUTER JOIN
dim.dimEmployee AS dimEmployee_2 ON fact.Incident.[Caller ID Email] = dimEmployee_2.[Email Address] LEFT OUTER JOIN
dim.dimDate AS dimDate_3 ON fact.Incident.[Updated Datekey] = dimDate_3.DateKey
Я использую следующий код для проверки дубликатов:
SELECT count (sys_id), номер ОТ группы [ALJAZEERA \ Naeemf]. [Запросы иерархии] по (sys_id), число с числом (sys_id)> 1
Пример набора данных результатов выглядит следующим образом:
нет
(Без названия колонки) номер 2 REQ0035412 2 REQ0032389 2 REQ0031000 2 REQ0047666 2 REQ0039400 2 REQ0030341 2 REQ0044462 2 REQ0026023 2 REQ0044207 2 REQ0020707 2 REQ0028762 2 REQ0043741 2 REQ0016740 2 REQ0027287 2 REQ0029590 2 REQ0050115 2 REQ0047027 2 REQ0018817 2 REQ0042548 2 REQ0025433 2 REQ0030387 2 REQ0042481 2 REQ0039159 2 REQ0042938 2 REQ0042648 2 REQ0043439 2 REQ0012954 2 REQ0031663 2 REQ0035056 2 REQ0021218 2 REQ0052394 2 REQ0034172 2 REQ0022032 2 REQ0013801 2 REQ0051336 2 REQ0013728 2 REQ0017371 2 REQ0047735 2 REQ0027745 2 REQ0045043 2 REQ0032863
Thera - всего 716 повторяющихся строк. Тем не менее, я поделюсь лишь несколькими примерами данных
sys_id - это уникальный идентификатор!
Спасибо за чтение и любую помощь, которую вы можете оказать!