请教一个sql 简单问题
declare @a int
select @a = count(id) from achivevment group by subjectID
select @a as 考试人数,count(id) as 考试人数,count(id)/@a as 通过率 from achivevment where achivevment> =60 and subjectID=1001 group by subjectID
显示的结果里百分比是0 怎么回事呢 有没有更简便的写法 有人告诉我可以不用变量就能写出来
10 80
[解决办法]
create table table1(学号 int, 科目id varchar(10), 成绩 int)
insert table1 select 1, '1001 ', 85
union all select 1, '1002 ', 87
union all select 2, '1001 ', 56
union all select 2, '1002 ', 88
select 考试人数,通过人数,(cast(cast((通过人数*100.0/考试人数)as dec(18,2))as varchar(5))+ '% ')通过率
from(select (select count(distinct 学号) from table1)考试人数, count(*)通过人数
from table1 where 科目id= '1001 ' and 成绩> =60)a