求一关于筛选费用异常的存储过程。
用于每个地点的上月费用和本月费用比较,当本月费用/上月费用>2时 筛选出该地点,以及本月费用。谢谢各位啊~ 
表结构如下:
表名:Cost
列名:StationID  地点名称
      Costs      当月费用
      Time       费用发生时间

解决方案 »

  1.   

    表名:Cost
    列名:StationID  地点名称
          Costs      当月费用
          Time       费用发生时间
    --表名:Cost
    --列名:StationID  地点名称
    --      Costs      当月费用
    --      CostTime   费用发生时间
    create procedure select_Cost_By_Condition
    (
    @NowTime datetime
    )
    asselect A.Costs,A.StationID from
    (select * from Cost where CostTime=@NowTime) as A, 
    (select * from Cost where CostTime= Dateadd(month,-1,@NowTime))as B
    where A.StationID=B.StationID and A.Costs/B.Costs>2