ddd表如下
品名 只数 重量 单价 计价类别
aa   11   11    0.11  只数
bb   11   11    0.11  重量
cc   11   11    0.11  重量
请问如何根据以下的条件,查询出数据
当计价类别='只数' 重量>10
当计价类别='重量' 只数>10
最好能用一条select 实现

解决方案 »

  1.   


    select * from tb
    where 
       case when 计价类别='只数' then 重量>10 
            when 计价类别='重量' then 只数>10
      

  2.   

    手误select * from ddd
    where 
       case when 计价类别='只数' then 重量>10 
            when 计价类别='重量' then 只数>10
       end
      

  3.   

    declare @tb table(品名 varchar(20),只数 int,重量 int,单价 decimal(3,2),计价类别 varchar(20))insert into @tb
    select 'aa','11','11','0.11','只数'
    union all select 'bb','11','11','0.11','重量'
    union all select 'cc','11','11','0.11','重量'select *
    from @tb
    where case when 计价类别 = '只数' then 重量>10
          when 计价类别 = '重量' then 只数>10
          end
      

  4.   

    我的意思是
    当计价类别='只数' 时,只执行' 重量>10'
    当计价类别='重量' 时,只执行' 只数>10'
    根据计价类别来执行相应的过滤条件。ddd表如下 
    品名 只数 重量 单价 计价类别 
    aa   0  11    0.11  只数 
    bb  11  0   0.11  重量 
    cc  11  8    0.11  重量
    dd  11  11    0.11  重量 如只数>0 和重量>10,则查询出来的结果如下品名 只数 重量 单价 计价类别 
    dd  11  11    0.11  重量 
      

  5.   

    declare @tb table(品名 varchar(20),只数 int,重量 int,单价 decimal(3,2),计价类别 varchar(20))insert into @tb
    select 'aa','11','11','0.11','只数'
    union all select 'bb','9','11','0.11','重量'
    union all select 'cc','11','9','0.11','重量'select *
    from @tb
    where case 计价类别 when  '只数' then  重量
                    when '重量' then  只数
             end >10
      

  6.   

    create table ddd(品名 char(10),只数 int,重量 int,单价 float,计价类别 char(20))
    insert ddd
    select 'aa',11,11,0.11,'只数' union all
    select 'aa',11,9,0.11,'只数' union all
    select 'bb',11,11,0.11,'重量' union all
    select 'cc',9,11,0.11,'重量'select * from ddd where (计价类别='只数'and 重量>10) or (计价类别='重量'and 只数>10) 结果:品名         只数          重量          单价                     计价类别
    ---------- ----------- ----------- ---------------------- --------------------
    aa         11          11          0.11                   只数                
    bb         11          11          0.11                   重量