Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于Sql Server 2008中的条件查找和_Sql_Sql Server_Sql Server 2008_Tsql - Fatal编程技术网

基于Sql Server 2008中的条件查找和

基于Sql Server 2008中的条件查找和,sql,sql-server,sql-server-2008,tsql,Sql,Sql Server,Sql Server 2008,Tsql,我的表中有这些列 Person Agent Unit BSP Discount 实际上,我必须计算人员的激励。在578以上的情况下说。因为它总共预订了4个单位,其中3个是经纪人,1个是个人。 因此,从经纪人的角度来看,他的激励将是每单位2500卢比,即3*2500=7500。 现在是折扣部分。见以下几点: 条件: 如果未给予折扣,将分配不到1%的BSP用于激励销售人员 如果预订折扣在0.1%到1%之间,将分配0.75%的BSP用于激励销售

我的表中有这些列

Person      Agent     Unit        BSP            Discount

实际上,我必须计算
人员的激励。在578以上的情况下说。因为它总共预订了4个单位,其中3个是经纪人,1个是个人。
因此,从经纪人的角度来看,他的激励将是每单位2500卢比,即3*2500=7500。
现在是折扣部分。见以下几点:

条件:

  • 如果未给予折扣,将分配不到1%的BSP用于激励销售人员

  • 如果预订折扣在0.1%到1%之间,将分配0.75%的BSP用于激励销售人员

  • 如果预订折扣在1.1%到2%之间,将分配0.50%的BSP用于激励销售人员

  • 如果预订折扣在2%和2%以上,则低于 BSP将用于激励销售人员

  • 在上表中,我们清楚地看到578预订了4套,其中两套有折扣,两套没有折扣

    因此,他的激励将计算为:

      var incentive = total_no_of_units_booked_with_agent * 2500;
    
    // since there might be a possibility that more than one units can be
    // booked by a sales person.No we have to find if there is any discount 
    // applied there, if its there, then extract the incentive for each unit 
    //and total it using the above condition. For table shown we have
    //since it has 4 records
    
      incentive = incentive + (.75% of BSP)+ (.75%of BSP)+(1% of BSP)+(1%of BSP) 
    

    对于条件和,只需使用sum并在其中包含CASE语句即可强制执行条件

    SELECT
      person,
      SUM(CASE WHEN discount  = 0.00 THEN 0.0100 * bsp
               WHEN discount <= 0.01 THEN 0.0075 * bsp
               WHEN discount <= 0.02 THEN 0.0050 * bsp
                                     ELSE 0.0025 * bsp END
          +
          CASE WHEN agent <> 0       THEN 2500.0
                                     ELSE    0.0       END)  AS incentive
    FROM
      yourTable
    GROUP BY
      person
    
    选择
    人,
    总额(折扣=0.00然后为0.0100*bsp时的情况)
    
    当折扣用于条件和时,只需使用包含CASE语句的sum来强制执行您的条件

    SELECT
      person,
      SUM(CASE WHEN discount  = 0.00 THEN 0.0100 * bsp
               WHEN discount <= 0.01 THEN 0.0075 * bsp
               WHEN discount <= 0.02 THEN 0.0050 * bsp
                                     ELSE 0.0025 * bsp END
          +
          CASE WHEN agent <> 0       THEN 2500.0
                                     ELSE    0.0       END)  AS incentive
    FROM
      yourTable
    GROUP BY
      person
    
    选择
    人,
    总额(折扣=0.00然后为0.0100*bsp时的情况)
    
    什么时候可以显示除“问题”一词之外的所需结果?@AaronBertrand查看我的更新问题您可以显示除“问题”一词之外的所需结果吗?@AaronBertrand查看我的更新问题