select 
case when lx=10 then je else 0 end as 销售金额,
case when lx=30 then sl else 0 end as 销售数量,
case when lx=30 then je else 0 end as 销售成本,
case when lx=11 then sl else 0 end as 销售数量_批发,
.....
form ywlx另外就是联表啦,要求机子一定要好,不好的话,跑死你,呵呵:)

解决方案 »

  1.   

    请问有没有比这更高效的SQL语句,如果用你这种方法的话,是可以实现的,但速度还产不太快!
      

  2.   

    第一张表SPPCR的ID字段建立索引,在第二张表YWLX的ID和LX建立索引
    建立存储过程
    create proc AAA
    as
    select .... 
    from  SPPCR
    join ....
    where LX=10 
    union 
    select .... 
    from  SPPCR
    join ....
    where LX=30
    union
    select .... 
    from  SPPCR
    join ....
    where LX=11 
    union
    select .... 
    from  SPPCR
    join ....
    where LX=7
    这样做会快点。
      

  3.   

    谢谢CMIC(大象),谢谢大家,我先试试。
      

  4.   

    如果真的是上百万的表  算了 用case你的速度不知道有多么的慢......
      建议你修改数据库结构  把该表分成四个表!