Build conditional SQL which can highlight a day with different hoursofoperation
<p>Suppose we have hierarchical relation among, ID1, ID2 and ID3. For each of ID3, we have 7 days work hours slot viz. Start and End. For most parts start and end time are same for all the days.</p>

<pre><code>ID1 -&gt; Multiple ID2
ID2 -&gt; Multiple ID3
ID3 -&gt; Min 7 records 
</code></pre>

<p>I am trying to query and find ID1s which have at least one day with different start and end time.</p>

<p>I tried using group by and distinct on ID3 table and nesting back to ID1 but it does not seems to be an effective approach. </p>

<p>Can i do using joins clubbed with conditional approach? </p>

<p>-Thanks.</p>

<p>Additional Details: There are 3 seperate tables having ID1, ID2 and ID3 as their PKs. </p>

<p>Lets say ID1 is BusinessID, ID2 is LineOfBusiness and ID3 is StoreID. Now each StoreID we have 7 days of store open and close times in ID3Table.</p>

<p>I am looking to find businessID for which 2 LineOfBusiness operate on different timings.</p>

<p>I tried putting distinct on combination of start and end time and grouped the result based on count. I mean less then 7  means some day is different. I took ID back to fine corresponding ID1 for that. This approach uses nested queries.</p>

<p>I am hoping to find  solution based on Join.</p>

<p>Hope this adds more clarity in the question. Thanks!</p>