我想在
CREATE procedure report_KM
@m_begin int,
@m_end int,
@m_date  varchar(20),
@m_startID int,
@m_endID int,
@m_FJIndex  varchar(150),
@m_LineSpeed  varchar(100)as
declare @minclass as int 
select @minclass=min(class) from table1
select id=max(id),km=km,
                   speed=?????????????????????? //speed 为type=1时候的值
           into #t3
           from table1 where type>=0 and type<=3  group by idspeed 该怎么写了,请朋友指点了,小弟刚从事这方面的工作

解决方案 »

  1.   

    CREATE procedure report_KM
    @m_begin int,
    @m_end int,
    @m_date  varchar(20),
    @m_startID int,
    @m_endID int,
    @m_FJIndex  varchar(150),
    @m_LineSpeed  varchar(100)as
    declare @minclass as int 
    select @minclass=min(class) from table1
    select id=max(id),km=km,
                       speed=max(case when type=1 then speed else null end)
               into #t3
               from table1 where type>=0 and type<=3  group by id
      

  2.   

    能帮我注释一下
         speed=max(case when type=1 then speed else null end)
    这一行吗?谢谢了
      

  3.   

    就是max(case when type=1 then speed else null end)什么意思,便于我以后学习
      

  4.   

    case when判断type=1返回speed的值,否则返回null,取最大就是type=1的值了(仅它有值)
      

  5.   

    我自己写的时候就是写了"case when type=1 then speed else null end"难怪它老是提示什么聚合函数的错误,那也能写min(case when type=1 then speed else null end)是吧.谢谢提示.