草飘飘:查出那样的结果是没办法用DBGRID显示出来的,临时表不合适,
不如直接查出你想要的结果
select distinct 姓名,
(select count(*) from table as t1 where t1.成绩=‘A’ and t1.姓名=t.姓名)as 'A',
(select count(*) from table as t2 where t2.成绩=‘B’ and t2.姓名=t.姓名)as 'B',
(select count(*) from table as t3 where t3.成绩=‘C’ and t3.姓名=t.姓名)as 'C',
from table as t
或者象剑风那样,可以不写存储过程。
我可以用sql server存储过程.
select 姓名,
sum(case 成绩 when 'A' then 1 end)'A',
sum(case 成绩 when 'B' then 1 end)'B',
sum(case 成绩 when 'C' then 1 end)'C'
from 表
group by 姓名