I'm trying to pull information on repeat dispatches and can't seem to come up with a simple solution to pull my data for a report.
I have the following table:
tblMaster15
ID | Equipment
----------------
1 | Sink
----------------
2 | Grill
And another table with location info that I have to join on using ID:
tblMaster15_ABData
ID | Unit | Region
--------------------
1 | 600 | 6000
--------------------
2 | 601 | 7000
And I'm trying to produce a list of the ID, Unit, and Equipment but only when the Unit and Equipment are the same more than 3 times in a given time period.
I've tried the following but it seems to be giving me everything, not just where the count is > 3.
select m.mrid, a.unit, a.Region, m.Equipment
from MASTER36 m
join MASTER36_ABDATA a
on m.mrid = a.mrid
, (select a.unit, m.Equipment
from MASTER36 m
join MASTER36_ABDATA a
on m.mrid = a.mrid
group by a.unit, m.Equipment
having count(*) > 3
) T2
where a.unit = t2.unit
and m.Equipment = t2.Equipment
and mrSUBMITDATE between '2/7/17' and '3/7/17'
and mrstatus <> 'DELETED'
and mrstatus <> 'Canceled'
and m.Equipment <> 'BLDNG
I did not think you would need status or submit date. The status is closed or open. Submit date in this format: 2017-01-01 00:50:24.000
I am using SQL Server 2012.