select (A.sl*B.jg)as zje from A,B,C 
where A.cid=C.id and A.bid=B.id 
      and (C.no in('001','002','003') OR C.no in('004','005','006') OR C.no in('007','008','009'))

解决方案 »

  1.   

    C.no in('001','002','003')  
    C.no in('004','005','006') 
    C.no in('007','008','009')  
    根据这三个条件,得到三个zje数据,如果某一个没有数据的时候,得到数据0
      

  2.   

    select (A.sl*B.jg)as zje from A,B,C where A.cid=C.id and A.bid=B.id and C.no in('001','002','003') 
    union all
    select (A.sl*B.jg) as zje from A,B,C where A.cid=C.id and A.bid=B.id and C.no in('004','005','006') 
    union all
    select (A.sl*B.jg) as zje from A,B,C where A.cid=C.id and A.bid=B.id and C.no in('007','008','009')  
    ==>
    select (A.sl*B.jg) as zje from A,B,C 
    where A.cid=C.id and A.bid=B.id 
          and (C.no in('001','002','003') OR C.no in('004','005','006') OR C.no in('007','008','009')) 
    ==>
    select (A.sl*B.jg) as zje from A,B,C 
    where A.cid=C.id and A.bid=B.id 
          and C.no in('001','002','003','004','005','006,'007','008','009') 
      

  3.   

    表A:cid   bid  sl
          1    1   5
          2    2   3
          3    3   2表B:id     jg
         1     10
         2     15
         3     20表C:id     no
         1      001
         2      005
         3      006这时候得到的结果我希望是:50
                           85
                           0
    或者是:50  85  0
      

  4.   


    select SUM(CASE WHEN C.NO IN ('001','002','003') THEN A.sl*B.jg ELSE 0 END),
           SUM(CASE WHEN C.NO IN ('004','005','006') THEN A.sl*B.jg ELSE 0 END),
           SUM(CASE WHEN C.NO IN ('007','008','009') THEN A.sl*B.jg ESLE 0 END)
    from A,B,C 
    where A.cid=C.id and A.bid=B.id 
      

  5.   

    非常感谢,zanyzyg的方法可行!