Link to home
Start Free TrialLog in
Avatar of tanj1035
tanj1035

asked on

SQL, how to sum up the column when the value >=5

Hi Experts, I want the expected result to sum up values when "days before test drive"  >=5. How can I modify my query? Thanks.


select count (dealID) as RequestedTestDrive,daysbeforetestdrive
from 
(select distinct d.dealid, datediff(day, max(cast(t.createdon as date)), max(cast (t.appointmentlocaltime as date))) as daysbeforetestdrive
from [MakeMyDeal_com].[dbo].[TestDrivelocal] t
inner join Mmd_feed..dealview d on t.dealid=d.dealid 
inner join Mmd_feed..dart dt on dt.dealerid=d.dealerid
where cast(t.createdon as date)>=@StartDate and cast(t.createdon as date)<=@EndDate
and d.dealstatus='sent'
and d.alternatedeal ='no'
and d.manualdeal='no'
group by d.dealid)as t
group by daysbeforetestdrive

Open in new window

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tanj1035
tanj1035

ASKER

It works!!!Thanks a lot.