NEED SQL QUERY FOR DESIRED OUTPUT : <p>Below is the sample data which gets filled into sql server database from PLC machine. DATETIME, CYCLETIME(TIME TAKEN TO PRODUCE THAT MATERIAL) AND SHIFT</p>

<p><a href="https://i.stack.imgur.com/T1UMw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T1UMw.png" alt="enter image description here"></a></p>

<p>There are 3 shifts in company A(6:30Am to 2:30PM), B(2:30 to 10:30), C(10:30 to 6:30AM).Only C shift sample data is shown above </p>

<p>when i take C Shift count, my query should take next day data also till 6:30AM time. Where as A shift should take current day data starting from 6:30Am to 2:30Pm.Where as B shift should take current day data starting from 2:31pm to 10:30PM.</p>

<p>QUANITY shown below IS COUNT OF ROWS in each shift.</p>

<p>DESIRED OUTPUT 1: SHIFTWISE DATA
<a href="https://i.stack.imgur.com/dMRDL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dMRDL.png" alt="enter image description here"></a></p>

<p>DESIRED OUTPUT 2: DAYWISE DATA
<a href="https://i.stack.imgur.com/twvxf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/twvxf.png" alt="enter image description here"></a></p>
