0

このクエリの出力を結合するには、ヘルプが必要です。どのように実行できますか??TQ

select facility, route, operation, script_id 
from F_ROUTEOPER
where facility = 'A01' and operation in ('6910','7976')
AND src_erase_date is null
and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)  
AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'
AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')


select facility, route, operation, script_id 
from F_ROUTEOPER
where facility = 'A01' and operation in ('6912','7976') 
AND src_erase_date is null
and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)  
AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'
AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')

select facility, route, operation, script_id 
from F_ROUTEOPER
where facility = 'A01' and operation in ('7344','7976') 
AND src_erase_date is null
and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)  
AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'
AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')

select facility, route, operation, script_id 
from F_ROUTEOPER
where facility = 'A01' and operation in ('8344','7976')
AND src_erase_date is null
and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)  
AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%'
AND route NOT LIKE 'BLB%' AND route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
4

5 に答える 5

2

すべてのoperation値を 1 つの IN に結合します。つまり、

operation in ('6910','7976','6912','7344','8344')

他の条件はまったく同じです。完全なクエリ

select facility, route, operation, script_id 
  from F_ROUTEOPER
 where facility = 'A01'
   and operation in ('6910','7976','6912','7344','8344')
   AND src_erase_date is null
   and (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)  
   AND (route NOT LIKE '9EL%' AND
        route NOT LIKE '9TB%' AND
        route NOT LIKE 'BLB%' AND
        route NOT LIKE 'BWR%' AND
        route NOT LIKE 'CRL%')
于 2012-11-05T09:13:16.650 に答える
2

キーワード UNION は、あなたにぴったりです。こちらのドキュメントをご覧ください - http://dev.mysql.com/doc/refman/5.0/en/union.html

于 2012-11-05T09:15:11.040 に答える
1

4 つのクエリは predicateAND operation In ..を除いて同じように見えます。次のように、この述語フォームを 4 つのクエリから組み合わせることができます。

select facility, route, operation, script_id 
from F_ROUTEOPER
where facility = 'A01' and operation in ('6910','7976', '6912', '8344','7976')
...

ただし、必要に応じてUNION(implicit distinctを使用したりUNION ALL、異なるクエリの結果を組み合わせたりすることができます。

于 2012-11-05T09:14:24.247 に答える
1

の値をoperation1 つの に結合しますIN

select facility, route, operation, script_id 
from F_ROUTEOPER
where facility = 'A01' and operation in ('6910','7976', '6912', '7344', '8344') 
    AND src_erase_date is null 
    AND (script_id not in ('PHQ-LOTCHKRV','PHQ-LOTCHK') or script_id is null)  
    AND (route NOT LIKE '9EL%' AND route NOT LIKE '9TB%' AND route NOT LIKE 'BLB%' AND 
         route NOT LIKE 'BWR%' AND route NOT LIKE 'CRL%')
于 2012-11-05T09:15:04.917 に答える
0

すべてのクエリの列数が同じで、列名とデータ型が同じである場合は、UNIONまたはを使用します。UNION ALL

select col1,col2,col3 from table1 
union
select col4 as col1,col5 as col2,col6 as col3 from table 2
于 2012-11-05T09:12:18.200 に答える