日期:2014-05-17 浏览次数:20698 次
if object_id('[ZK]') is not null drop table [ZK] go create table [ZK] (数量 int,折扣 int) insert into [ZK] select 2,10 union all select 4,15 union all select 6,20 select * from [ZK] declare @i int set @i = 2 select 数量,折扣 from ZK where 数量 = @i /* 数量 折扣 2 10*/
------解决方案--------------------
declare @i int set @i=3 if @i<2 select 1[数量],0[折扣] else if @i<4 select @i [数量],折扣 from zk where 数量=2 else if @i<6 select @i [数量],折扣 from zk where 数量=4 else select @i [数量],折扣 from zk where 数量=6
------解决方案--------------------
declare @qty int,@discount int select @qty=1; select @discount=isnull((select top 1 折扣 from 你的表 where t.数量<=@qty order by 数量 desc),0); select @qty 数量, @discount 折扣;