1

私は正常に動作するこの既存のクエリを持っています:

SELECT data_tool.name as tool,
       MIN(data_cst.date_time) "start",
       MAX(data_cst.date_time) "end",
       data_cst.recipe_id,
       data_target.name as target,
       data_lot.name as lot,
       data_wafer.name as wafer,
       data_measparams.name as mp
FROM data_cst
INNER JOIN data_tool ON data_tool.id = data_cst.tool_id
INNER JOIN data_target ON data_target.id = data_cst.target_name_id
INNER JOIN data_lot ON data_lot.id = data_cst.lot_id
INNER JOIN data_wafer ON data_wafer.id = data_cst.wafer_id
INNER JOIN data_measparams ON data_measparams.id = data_cst.meas_params_name_id
WHERE data_target.id IN (130, 539)
AND data_cst.date_time BETWEEN '2010-01-11 00:00:00' AND '2013-01-11 23:59:59'
AND data_cst.tool_id IN (14,16)
GROUP BY wafer_id, data_cst.lot_id, data_file_id, target_name_id
HAVING count(*) < 100
ORDER BY start, tool

今、私はそれに何かを追加する必要があります。、、、 、およびevent_message_idxという列を持つ別のテーブル があります。recipe_idlot_idtool_iddate_timemessage_idx

そのテーブル内の行数と、上記のクエリ on and hasに結合された行数を調べる必要がありmessage_idx = 'OM' ます。message_idx = 'SEM'recipe_id, lot_id, tool_iddate_time between start and end

1 つのクエリでこれを行う方法を理解できませんでした (これらのテーブルは非常に大きく、このシステムでは過去にサブクエリのパフォーマンスが低かったため、サブクエリを使用することをお勧めします)。

私はこのような左結合で遊んでいます:

SELECT data_tool.name as tool,
       MIN(data_cst.date_time) "start",
       MAX(data_cst.date_time) "end",
       data_cst.recipe_id,
       data_target.name as target,
       data_lot.name as lot,
       data_wafer.name as wafer,
       data_measparams.name as mp,
       event_message_idx.message_idx,
       COUNT(event_message_idx.message_idx)
FROM data_cst
LEFT JOIN event_message_idx
  ON event_message_idx.recipe_id = data_cst.recipe_id
  AND event_message_idx.message_idx IN ('OM', 'SEM')
  AND event_message_idx.lot_id = data_cst.lot_id
  AND event_message_idx.tool_id = data_cst.tool_id
INNER JOIN data_tool ON data_tool.id = data_cst.tool_id
INNER JOIN data_target ON data_target.id = data_cst.target_name_id
INNER JOIN data_lot ON data_lot.id = data_cst.lot_id
INNER JOIN data_wafer ON data_wafer.id = data_cst.wafer_id
INNER JOIN data_measparams ON data_measparams.id = data_cst.meas_params_name_id
WHERE data_target.id IN (130, 539)
AND data_cst.date_time BETWEEN '2010-01-11 00:00:00' AND '2013-01-11 23:59:59'
AND data_cst.tool_id IN (14,16)
GROUP BY wafer_id, data_cst.lot_id, data_file_id, target_name_id,
event_message_idx.message_idx
HAVING count(*) < 100
ORDER BY start, tool

しかし、ここには 2 つの問題があります。

  • 必要な行数の 2 倍を取得します。1 つは OM 用、もう 1 つは SEM 用です。
  • 私はそれを望んでいません-OMとSEMの行がいくつあるか知りたいだけです(実際には、0以上か0かどうかを知りたいだけです-実際の数は関係ありません)。

  • 日付範囲を考慮していません-開始と終了の間にある event_message_idx からの行のみをカウントしたいのですが、その方法がわかりません。

これは可能ですか?私はそうではないと考えており、2 つのクエリ (アプリが非常に複雑になります)、またはサブクエリ (これも書くのに苦労しています) を使用する必要があります。

4

1 に答える 1

2

サブクエリでそれらを計算します。

SELECT  data_tool.name as tool,
        MIN(data_cst.date_time) "start",
        MAX(data_cst.date_time) "end",
        data_cst.recipe_id,
        data_target.name as target,
        data_lot.name as lot,
        data_wafer.name as wafer,
        data_measparams.name as mp,
        COALESCE(a.totalOM, 0) totalOM,
        COALESCE(a.totalSEM, 0) totalSEM
FROM    data_cst
        INNER JOIN data_tool 
            ON data_tool.id = data_cst.tool_id
        INNER JOIN data_target 
            ON data_target.id = data_cst.target_name_id
        INNER JOIN data_lot 
            ON data_lot.id = data_cst.lot_id
        INNER JOIN data_wafer 
            ON data_wafer.id = data_cst.wafer_id
        INNER JOIN data_measparams 
            ON data_measparams.id = data_cst.meas_params_name_id
        LEFT JOIN 
        (
            SELECT  recipe_id, lot_id, tool_id,
                    SUM(CASE WHEN message_idx = 'OM' THEN 1 ELSE 0 END) totalOM,
                    SUM(CASE WHEN message_idx = 'SEM' THEN 1 ELSE 0 END) totalSEM
            FROM    event_message_idx
            WHERE   date_time BETWEEN '2010-01-11 00:00:00' AND '2013-01-11 23:59:59'
            GROUP   BY recipe_id, lot_id, tool_id
        ) a ON  data_cst.recipe_id = a.recipe_id AND
                data_cst.lot_id = a.lot_id AND
                data_cst.tool_id = a.tool_id 
WHERE   data_target.id IN (130, 539) AND 
        (data_cst.date_time BETWEEN '2010-01-11 00:00:00' AND '2013-01-11 23:59:59') AND 
        data_cst.tool_id IN (14,16)
GROUP   BY  wafer_id, data_cst.lot_id, data_file_id, target_name_id
HAVING  COUNT(*) < 100
ORDER   BY `start`, tool
于 2013-01-12T13:12:21.287 に答える