Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何组合这些SQL查询以便它可以显示一个输出?_Sql - Fatal编程技术网

如何组合这些SQL查询以便它可以显示一个输出?

如何组合这些SQL查询以便它可以显示一个输出?,sql,Sql,将此查询的输出组合在一起所需的帮助。如何完成?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) AN

将此查询的输出组合在一起所需的帮助。如何完成?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%')

如果所有查询具有相同的列数、相同的列名和相同的数据类型,则使用
UNION
UNION all

select col1,col2,col3 from table1 
union
select col4 as col1,col5 as col2,col6 as col3 from table 2

如果所有查询具有相同的列数、相同的列名和相同的数据类型,则使用
UNION
UNION all

select col1,col2,col3 from table1 
union
select col4 as col1,col5 as col2,col6 as col3 from table 2

将所有的
操作
值合并到一个in。。。i、 e

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%')

将所有的
操作
值合并到一个in。。。i、 e

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%')

除了谓词
和..
中的操作外,这四个查询似乎是相同的,您可以将此谓词组合成四个查询,如下所示:

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

但是,如果愿意,您可以使用
UNION
(隐式distinct或
UNION ALL
)来组合来自不同查询的结果。

这四个查询似乎是相同的。除了谓词
和..
中的操作之外,您可以将此谓词组合成四个查询,如下所示:

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

但是,如果愿意,您可以使用
UNION
(隐式distinct或
UNION ALL
组合来自不同查询的结果。

操作
的值组合在一个
中:

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%')

中的单个中组合操作的值:

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%')

关键字联盟对你来说应该很有用。
请查看此处的文档-

关键字UNION应该非常适合您。
看看这里的文档-

当你思考它时,这是一个愚蠢的问题,只需要一点逻辑。当你思考它时,这是一个愚蠢的问题,只需要一点逻辑。tq…我试过了,它工作了…很好。如果这是你需要的,你能接受这个答案吗?tq…我试过了,它工作了…很好。如果这是你想要的如果需要,你能接受这个答案吗?