sql server - How to find records exist with one date but not the other within the same table with sql -


i have table so:

locationid | createddate | headcount -----------+-------------+----------- 1          | 2017-6-5    | 12 3          | 2017-6-5    | 458 5          | 2017-6-5    | 125 1          | 2017-8-5    | 12 5          | 2017-8-5    | 458 

i need find locationids in table exist on particular date not exist in date. in table above i'd need return

3          | 2017-6-5    | 458 

i'm trying below, think may need use temp tables accomplish task.

select *  headcounts full outer join headcounts b on a.locationid = b.locationid a.createddate = '2017-6-5'   , b.createddate = '2017-6-5'   , a.locationid null    or b.locationid null 

any appreciated.

you can where not exists:

select  *    headcounts  h1 not exists (     select  *        headcounts  h2       h1.locationid = h2.locationid     ,     h1.createddate <> h2.createddate ) 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -