我想求出'椴木地板'和'柞木地板'的平均材积,如果椴木地板平均材积比柞木地板平均材积多50% 显示高
如果椴木地板平均材积和柞木地板平均材积比率在1.5~0.8之间 显示中
其它 显示低我的代码如下.select d1=avg(材积) from baohao where  zhipin='椴木地板'select z1=avg(材积) from baohao where  zhipin='柞木地板'case d1/z1   when d1/z1>0.5  then  print '高'
  when d1/z1>0.8 and d1/z1<1.5 then print '中'
  when d1/z1>1.5 then print '低'
end可是不能执行..大家来帮忙~~~

解决方案 »

  1.   

    print 
    case  
    when d1/z1>=0.5 then '高'
    when d1/z1>0.8 and d1/z1<1.5 then  '中'
    when d1/z1>1.5 then '低'
    else ''
    end
      

  2.   

    create table baohao
    (
    材积 numeric(10,1),
    zhipin varchar(20)
    )
    insert baohao
    select 2.0,'椴木地板' union all
    select 1.0,'椴木地板' union all
    select 0.4,'椴木地板' union all
    select 2.0,'柞木地板' union all
    select 1.0,'柞木地板' 
    select * from baohaoselect d1=avg(材积),zhipin into #T from baohao group by zhipin
    select case
           when (select d1 from #t where zhipin='椴木地板')/(select d1 from #t where zhipin='柞木地板')>0.5 then '高'
           end
    其他的自己加上,说实在的,还不是太明白你需求。
    你把你要的结果用表格的形式说一下啊-_-
      

  3.   

    to:
     hjw01592(风男) ( ) 信誉:100  2006-08-22 16:54:00  得分: 0  
     
     
       楼上,楼主意思是要根据比率分类啊
      
     上面的不对吗?
      

  4.   

    create table baohao
    (
    材积 numeric(10,1),
    zhipin varchar(20)
    )
    insert baohao
    select 2.0,'椴木地板' union all
    select 1.0,'椴木地板' union all
    select 0.4,'椴木地板' union all
    select 2.0,'柞木地板' union all
    select 1.0,'柞木地板' 
    select * from baohaodeclare @a numeric(10,1),
            @b numeric(10,1)
    select @a=avg(材积) from baohao where zhipin='椴木地板'
    select @b=avg(材积) from baohao where zhipin='柞木地板'
    select case when @a/@b>=1.5 then '低'
                when @a/@b>=0.8 and @a/@b<1.5 then '中'
                else '低' end
    自己看着改改吧  ^_^
      

  5.   

    select @d1=avg(材积) from baohao where  zhipin='椴木地板'select @z1=avg(材积) from baohao where  zhipin='柞木地板'select '椴木地板平均材积:柞木地板平均材积'=case when @d1/@z1>0.5  then  '高'
      when @d1/@z1>0.8 and @d1/@z1<1.5 then '中'
      when @d1/@z1>1.5 then '低'
      else '低'
    end