I'm trying to find a SQL query that will count the number of distinct start times that are at least 30 minutes different.
I have a number of employees that are paid a credit when they start work on at least three distinct times in a week, where the start time is at least 30 minutes different from the other start times. For example:
select count(distinct (CONVERT(VARCHAR(10), starttime, 108))), employeecode
from schedule
where CONVERT(VARCHAR(10), starttime, 108) >=
(select min(CONVERT(VARCHAR(10), dateadd (mi, 30, s2.starttime), 108)) from schedule s2)
group by starttime, employeecode
I am hoping to get a result with the employee code and the number of different and distinct start times. eg. Employeecode = 9999, Different Start times = 4 I have been bumbling through this and am yet to get something working...
Can anyone suggest where I am going wrong or a suitable solution that might help me? Thanks in advance for your help :)