select 车队、datepart(year,事故日期) as 年,datepart(month,事故日期) as 月  
into #Temp1 from 表1select 车队,年,月,count(*) as 次数
into #Temp2
from #Temp1select 车队,年,
sum(case when 月=1 then 次数 else 0 end) as 一月,
sum(case when 月=2 then 次数 else 0 end) as 二月,
...
sum(case when 月=12 then 次数 else 0 end) as 十二月
into #Temp3
from Temp2
group by 车队,年select a.车队,a.年,
a.一月,
convert(char(20),a.一月/b.车数*100)+'%' as 一月事故频率,
a.二月,
convert(char(20),a.二月/b.车数*100)+'%' as 二月事故频率,
...
a.十二月,
convert(char(20),a.十二月/b.车数*100)+'%' as 十二月事故频率
from #Temp3 a,表2 b
where a.车队=b.车队