2016-04-12 26 views
1
SELECT sum(sum(DATEDIFF(DAY,LeaveBreakup.StartDate,LeaveBreakup.EndDate)+1)) AS totalNoOfDays, 
     LeaveApplication.Id, 
     LeaveBreakup.StartDate, 
     LeaveBreakup.EndDate, 
     LeaveApplication.ReasonForLeave, 
     LeaveApplication.ProcessorComment, 
     Team.Name, 
     LeaveTypeDetail.Name 
FROM LeaveApplication 
INNER JOIN Employee ON LeaveApplication.Employee=Employee.Id 
INNER JOIN Team ON Employee.Team=Team.Id 
INNER JOIN LeaveBreakup ON LeaveApplication.Id=LeaveBreakup.LeaveApplication 
INNER JOIN LeaveTypeDetail ON LeaveBreakup.LeaveType=LeaveTypeDetail.LeaveType 
WHERE Employee.Team=5 
    AND LeaveStatus!=0 
    AND LeaveBreakup.StartDate BETWEEN '01-01-2016' AND '01-31-2016' 
    AND LeaveBreakup.WhichHalf=0 
GROUP BY LeaveApplication.Id, 
     LeaveBreakup.StartDate, 
     LeaveBreakup.EndDate, 
     LeaveApplication.ReasonForLeave, 
     LeaveApplication.ProcessorComment, 
     Team.Name, 
     LeaveTypeDetail.Name 
ORDER BY LeaveBreakup.StartDate 
+0

なぜ「合計」の「合計」が必要ですか?それは誤りです。 – HoneyBadger

+0

あなたはこれらの2 SUMを最初に必要としません。SUM(blah)+1 – Mihai

+0

私はちょうどその列 'totalNoOfDays'の総計を – akash

答えて

0

このようなことを試してみてください。

SELECT sum(totalNoOfDays) as total, 
a.Id, 
     a.StartDate, 
     a.EndDate, 
     a.ReasonForLeave, 
     a.ProcessorComment, 
     a.Name, 
     a.Name 
from 
select 
(
select sum(DATEDIFF(DAY,LeaveBreakup.StartDate,LeaveBreakup.EndDate)+1) AS totalNoOfDays, 
     LeaveApplication.Id, 
     LeaveBreakup.StartDate, 
     LeaveBreakup.EndDate, 
     LeaveApplication.ReasonForLeave, 
     LeaveApplication.ProcessorComment, 
     Team.Name, 
     LeaveTypeDetail.Name 
FROM LeaveApplication 
INNER JOIN Employee ON LeaveApplication.Employee=Employee.Id 
INNER JOIN Team ON Employee.Team=Team.Id 
INNER JOIN LeaveBreakup ON LeaveApplication.Id=LeaveBreakup.LeaveApplication 
INNER JOIN LeaveTypeDetail ON LeaveBreakup.LeaveType=LeaveTypeDetail.LeaveType 
WHERE Employee.Team=5 
    AND LeaveStatus!=0 
    AND LeaveBreakup.StartDate BETWEEN '01-01-2016' AND '01-31-2016' 
    AND LeaveBreakup.WhichHalf=0 
GROUP BY LeaveApplication.Id, 
     LeaveBreakup.StartDate, 
     LeaveBreakup.EndDate, 
     LeaveApplication.ReasonForLeave, 
     LeaveApplication.ProcessorComment, 
     Team.Name, 
     LeaveTypeDetail.Name 
)a 
group by 
a.Id, 
a.StartDate, 
a.EndDate, 
a.ReasonForLeave, 
a.ProcessorComment, 
a.Name, 
a.Name 
ORDER BY a.StartDate