This is a query that I’ve been using:
select serial_number, DAQ.qtag_no, min(TOH.start_time), order_number, DAQ.creation_time, qtag_status, ar_code, pro_foundin, pro_category, root_cause, remark from UNIT U
left JOIN WORK_ORDER WO ON WO.order_key = U.order_key
left join TRACKED_OBJECT_HISTORY TOH on TOH.tobj_key = U.unit_key
WHERE U.creation_time > '01/01/2012' AND U.creation_time < '07/20/2012'
AND order_number NOT LIKE '[R]%'
group by serial_number, qtag_no, order_number, DAQ.creation_time, qtag_status, ar_code, pro_foundin, pro_category, root_cause, remark
order by serial_number
Right now I get 3280 results.
In this setup, there are different stations, such as “Assembly,” “Diagnostics,” etc. My goal for the min(TOH.start_time) column is to return the first start time at the Assembly station, but currently it’s returning the first start time at ANY station. However, if I add another WHERE clause to specify the station (TOH.op_name = ‘Assembly’), it limits the number of results (down to 2700). I’d like to keep the 3280 results and instead for units not scanned in to the Assembly station, return NULL for min(TOH.start_time) column. I tried using the case function, but that requires me to include TOH.op_name in the group by clause, which I’m not looking for. Thanks!
You should just be able to add your condition to the left join I think, like this: