select '49年以前' 领取年份, 
       count(*) * 100 / (select count(*) from yourtable) 百分比 
from yourtable where edate < '1949-1-1'
union all
select 49年到90年' 领取年份, 
       count(*) * 100 / (select count(*) from yourtable) 百分比 
from yourtable where edate between '1949-1-1' and '1990-1-1'
union all
select '90年到现在' 领取年份, 
       count(*) * 100 / (select count(*) from yourtable) 百分比 
from yourtable where edate >= '1990-1-1'

解决方案 »

  1.   

    --工资的领取年份 是 年份 还是 日期 ?
    select sum((case when 工资的领取年份 <= 1949 then 1 else 0 end))
       as 领取年份49年以前,
       sum((case when 工资的领取年份 between 1949 + 1 and 1990 - 1 else 0 end))
       as 领取年份1950-1989年,
       sum((case when 工资的领取年份 >= 1990 else 0 end))
       as 领取年份1990年以后
      from tablename
      

  2.   

    --更正
    select round(sum((case when 工资的领取年份 <= 1949 then 1 else 0 end))
      / (select count(*) from tablename),2)
       as 领取年份49年以前,
       round(sum((case when 工资的领取年份 between 1949 + 1 and 1990 - 1 else 0 end))
      / (select count(*) from tablename),2)
       as 领取年份1950-1989年,
       round(sum((case when 工资的领取年份 >= 1990 else 0 end))
      / (select count(*) from tablename),2)
       as 领取年份1990年以后
      from tablename
      

  3.   

    select '49年以前' 领取年份, 
           cast((count(*) * 100 / (select count(*) from yourtable)) as varchar(10)) + '%' as 百分比 
    from yourtable where edate < '1949-1-1'
    union all
    select 49年到90年' , 
           cast((count(*) * 100 / (select count(*) from yourtable)) as varchar(10)) + '%'  
    from yourtable where edate between '1949-1-1' and '1990-1-1'
    union all
    select '90年到现在' , 
           cast((count(*) * 100 / (select count(*) from yourtable)) as varchar(10)) +'%' 
    from yourtable where edate >= '1990-1-1'
      

  4.   

    select avg(sum(工资))*100+'%' from table group by case when year(年份)<1949 then 'a' 
    when year(年份) between 1949 and 1990 
    when year(年份) between 1990 and year(getdate()) 
      

  5.   

    select avg(sum(工资))*100+'%' from table group by case when year(年份)<1949 then 'a' 
    when year(年份) between 1949 and 1990 then 'b'
    when year(年份) between 1990 and year(getdate()) then 'c'