У меня есть запрос, который работает правильно, и я получаю следующий вывод:
9 1116 JOHN 0590056093 9106809105 3 A NULL D
9 1117 SARA 0015562451 9203410410 3 A NULL D
9 1118 DAVID 5560101753 9375115360 3 B NULL D
После добавления столбца datediff
мой вывод выглядит следующим образом
9 1116 JOHN 0590056093 9106809105 3 A NULL D 10
9 1116 JOHN 0590056093 9106809105 3 A NULL D 1
9 1117 SARA 0015562451 9203410410 3 A NULL D 10
9 1117 SARA 0015562451 9203410410 3 A NULL D 1
9 1118 DAVID 5560101753 9375115360 3 B NULL D 10
9 1118 DAVID 5560101753 9375115360 3 B NULL D 1
Что такое причина отображения 1 в столбце datediff
?
Запрос:
select distinct t1.*, fs.Name+' '+ed.Academic as takhasos, Articles.Title, MT.Name as paye,
datediff(m,Projects.StartDateProject, Projects.EndDateProject) as datedif
from
(select RC.ID, RCU.UserID, u.Name + ' ' + u.Family AS NameFamily, u.UserName, u.Mobile, u.Email, groupED.IdMaghtae
from ResearchersCores AS RC LEFT OUTER JOIN
ResearchersCoreUsers AS RCU ON RC.ID = RCU.ResearchersCoreID LEFT OUTER JOIN
Users AS u ON u.Id = RCU.UserID LEFT OUTER JOIN
(SELECT Eductionals.UserID , Max(Eductionals.MaghtaeID) AS IdMaghtae
FROM Eductionals
GROUP BY Eductionals.UserID) groupED
ON u.Id = groupED.UserID
WHERE (RC.IsEnable = 1) AND (RCU.isEnable = 1) AND (RCU.RoleID = 5) ) t1 left outer join
Eductionals as ED ON ED.UserID = t1.UserID AND t1.IdMaghtae = ed.MaghtaeID left outer join
FieldStudies as FS ON ed.FieldStudy_ID = FS.ID left outer join
Articles ON Articles.UserID = t1.UserID left outer join
Projects ON Projects.RecordID = t1.ID and Projects.ControllerID = 8 left outer join
MaghtaeTahsilis MT On MT.ID = t1.IdMaghtae
where t1.id = 9
Я хочу следующий вывод
9 1116 JOHN 0590056093 9106809105 3 A NULL D 10
9 1117 SARA 0015562451 9203410410 3 A NULL D 10
9 1118 DAVID 5560101753 9375115360 3 B NULL D 10