select a.物料号,a.钢种,a.成材率,b.合格率
from(
select  qbmvc1 as 物料号,substring(qbmvc1,6,4) as 钢种,qbmnc1/100 as 成材率 
from mpmxva
where  qbmxid='ma120'
)a join(
select  qbmvc1 as 物料号,substring(qbmvc1,6,4) as 钢种,qbmnc1/100 as 成材率 
from mpmxva
where  qbmxid='ma122'
)b on a.物料号=b.物料号 and a.钢种=b.钢种

解决方案 »

  1.   

    select  qbmvc1 as 物料号,substring(qbmvc1,6,4) as 钢种,
    (case when qbmxid='ma120' then qbmnc1 end)/100 as 成材率,
    (case when qbmxid='ma122' then qbmnc1 end)/100 as 成材率,
     from mpmxva
      

  2.   

    select  qbmvc1 as 物料号,substring(qbmvc1,6,4) as 钢种,qbmnc1/100 as 成材率 , 0.0 合格率 from mpmxva
    where  qbmxid='ma120'
    union 
    select  qbmvc1 as 物料号,substring(qbmvc1,6,4) as 钢种,0.0 成材率, qbmnc1/100 as 合格率 from mpmxva
    where  qbmxid='ma122'
      

  3.   

    问题没说清楚你用什么条件决定qbmnc1/100 是成材率还是合格率的?
    写个case语句就能解决具体可以看联机帮助的case
      

  4.   

    select  qbmvc1 as 物料号,substring(qbmvc1,6,4) as 钢种, 成材率 = case 
     when qbmxid='ma120' then qbmnc1/100 else 0.0 end,合格率 =case 
    when qbmxid='ma122' then qbmnc1/100 else 0.0  end
    from mpmxva
      

  5.   

    多谢大家!
    zjcxc(: 邹建 :) 的是我要的结果,不过大家的我也要试试