0

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.

blackraven
  • 5,284
  • 7
  • 19
  • 45
  • Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements for all tables involved, relevant columns only) so the people who want to help you can recreate the problem and test their ideas. Also post the exact results you want from that data, and explain why you want those results from that data. Lastly, don't post any images as they cant be cut and pasted. – Beefstu Sep 06 '22 at 19:34
  • How do you want your aggregate columns to behave? If you add the timestamp the grain is going to break your aggregation as you just displayed. Do you want just time or date? Do you want the sum to pass the same over date, or date time? Can you post some sample data of how you want it to look? – VLOOKUP Sep 06 '22 at 19:46
  • Can you please describe in more detail what the desired timestamp should represent? I don't understand what you want to achieve with CURRENT_DATE+ROWNUM/24 ? (current_date is an Oracle function to return the servers current date and time; so it is not a persistent data of a specific row) – flyaround Sep 07 '22 at 21:34

0 Answers0