Code:
SELECT ...
FROM ...
WHERE sched_date > CURRENT DATE OR
( sched_date = CURRENT DATE AND sched_shift = 'C' )
ORDER BY sched_date ASC, sched_shift DESC
What is missing in this is the mechanism to pick only the first 3 rows for each machine. Depending on your specific DBMS, this may look differently. In standard SQL, you could identify the first 3 using a couple joins and MAX() aggregation function. In DB2, you could do something like this:
Code:
SELECT *
FROM ( SELECT ..., ROW_NUMBER OVER ( ORDER BY sched_date ASC, sched_shift DESC) AS rn
FROM ...
WHERE sched_date > CURRENT DATE OR
( sched_date = CURRENT DATE AND sched_shift = 'C' ) ) AS t
WHERE rn <= 3
ORDER BY sched_date ASC, sched_shift DESC