Oracle SQL - Timestamp splits query result into 2 rows, Need all in one with

83 views Asked by At

I need a time-based query (Random or Current) with all results in one row. My current query is as follows:

WITH started AS 
(
  SELECT f.*, CURRENT_DATE + ROWNUM / 24
  FROM 
  (
    SELECT
      d.route_name,
      d.op_name,
      d.route_step_name,
      nvl(MAX(DECODE(d.complete_reason, NULL, d.op_STARTS)), 0) started_units,
      round(nvl(MAX(DECODE(d.complete_reason, 'PASS', d.op_complete)), 0) / d.op_starts * 100, 2) yield
    FROM 
    (
      SELECT route_name,
        op_name,
        route_step_name,
        complete_reason,
        complete_quantity,
        sum(start_quantity) OVER(PARTITION BY route_name, op_name, COMPLETE_REASON) op_starts,
        sum(complete_quantity) OVER(PARTITION BY route_name, op_name, COMPLETE_REASON ) op_complete
      FROM FTPC_LT_PRDACT.tracked_object_history
      WHERE route_name = 'HEADER FINAL ASSEMBLY'
        AND OP_NAME NOT LIKE '%DISPOSITION%'
        and (tobj_type = 'Lot')
        AND xfr_insert_pid IN 
        (
          SELECT xfr_start_id
          FROM FTPC_LT_PRDACT.xfr_interval_id
          WHERE last_modified_time <= SYSDATE
            AND OP_NAME NOT LIKE '%DISPOSITION%'
            and complete_reason = 'PASS' OR complete_reason IS NULL
        ) 
    ) d
    GROUP BY d.route_name, d.op_name, d.route_step_name, complete_reason, d.op_starts
    ORDER BY d.route_step_name 
  ) f 
),
queued AS 
(
  SELECT 
    ts.route_name,
    ts.queue_name,
    o.op_name,
    sum (th.complete_quantity) queued_units
  FROM
  FTPC_LT_PRDACT.tracked_object_HISTORY   th,
  FTPC_LT_PRDACT.tracked_object_status   ts,
  FTPC_LT_PRDACT.route_arc               a,
  FTPC_LT_PRDACT.route_step              r,
  FTPC_LT_PRDACT.operation               o,
  FTPC_LT_PRDACT.lot l 
  WHERE r.op_key = o.op_key
    and l.lot_key = th.tobj_key
    AND a.to_node_key = r.route_step_key
    AND a.from_node_key = ts.queue_key
    and th.tobj_history_key = ts.tobj_history_key
    AND a.main_path = 1 
    AND (ts.tobj_type = 'Lot')
    AND O.OP_NAME NOT LIKE '%DISPOSITION%'
    and th.route_name = 'HEADER FINAL ASSEMBLY'
  GROUP BY ts.route_name, ts.queue_name, o.op_name
)
SELECT
  started.route_name,
  started.op_name,
  started.route_step_name,
  max(started.yield) started_yield,
  max(started.started_units) started_units,
  case when queued.queue_name is NULL then 'N/A' else queued.queue_name end QUEUE_NAME,
  case when queued.queued_units is NULL then 0 else queued.queued_units end QUEUED_UNITS
FROM started 
left JOIN queued ON started.op_name = queued.op_name 
group by started.route_name, started.op_name, started.route_step_name, queued.queue_name, QUEUED_UNITS
order by started.route_step_name asc
;

Current Query (as expected) but missing timestamp:
https://i.stack.imgur.com/vx3zl.png

I need to have a timestamp for each individual row for a different application to display the results. Any help would be greatly appreciated! When I try to add a timestamp my query is altered:

Query once timestamp is added:
https://i.stack.imgur.com/Qwfpf.png

Edit: I need to display the query in a visualization tool. That tool is time based and will skew the table results unless there is a datetime associated with each field. The date time value can be random, but cannot be the same for each result.

The query is to be displayed on a live dashboard, every time the application is refreshed, the query is expected to be updated.

0

There are 0 answers