单条命令执行
1.select wo.*,batch-sum(de.capacity) from worder wo,details de where wo.line=132 and wo.finish='no' and wo.workorder=de.workorder
执行结果:
2.select worder.*,batch from worder where line=12 and finish='no' and workorder not in(select workorder from details group by workorder)
执行结果:
联合查询
select wo.*,batch-sum(de.capacity) from worder wo,details de where wo.line=12 and wo.finish='no' and wo.workorder=de.workorder
union all
select worder.*,batch from worder where line=12 and finish='no' and workorder not in(select workorder from details group by workorder)
执行结果:
联合查询 union all 不是对这两行的结果进行简单组合吗,这是怎么一回事?

解决方案 »

  1.   

    详细说明,试试SELECT * FROM (
    select wo.*,batch-sum(de.capacity) from worder wo,details de where wo.line=12 and wo.finish='no' and wo.workorder=de.workorder) A
    union all
    SELECT * FROM (
    select worder.*,batch from worder where line=12 and finish='no' and workorder not in(select workorder from details group by workorder))B
      

  2.   

    就是单条查询时,因为都限制了字段 line=12  进行了查询
    1.的查询结果是空的,
    2.的查询结果是一条,然而进行联合查询时。就应该返回的是
    2.的这一条查询的结果呀,为何它还返回了上一行,很奇怪的一行,只有line有值,而且line 值根本就不是我限定的12.(我限定的是12 呀。)
      

  3.   

    1.代表查询
    select wo.*,batch-sum(de.capacity) from worder wo,details de where wo.line=12 and wo.finish='no' and wo.workorder=de.workorder2.代表查询
    select worder.*,batch from worder where line=12 and finish='no' and workorder not in(select workorder from details group by workorder
      

  4.   

    WWWWA 
    aaaa 等级: 
    结帖率:100% 21321  
    #2 得分:0 回复于: 2012-12-11 08:32:56  
    详细说明,试试SELECT * FROM (
    select wo.*,batch-sum(de.capacity) from worder wo,details de where wo.line=12 and wo.finish='no' and wo.workorder=de.workorder) A
    union all
    SELECT * FROM (
    select worder.*,batch from worder where line=12 and finish='no' and workorder not in(select workorder from details group by workorder))B
     
      

  5.   

    用二楼大哥的那个查询,在mysql 第二句 中会报 batch 重复的列