.header on
.mode column
select 
  substr(game_id,4,4) as year
 ,bat_id as batter
 ,sum(case when pa_new_fl = 'T' then 1 else 0 end) as PA 
 ,sum(case when ab_fl = 'T' then 1 else 0 end) as AB
 ,sum(case when h_cd > 0 then 1 else 0 end) as H
 ,sum(case when h_cd = 2 then 1 else 0 end) as DBL
 ,sum(case when h_cd = 3 then 1 else 0 end) as TRP
 ,sum(case when h_cd = 4 then 1 else 0 end) as HR
 ,sum(case when event_cd = 3 then 1 else 0 end) as SO
 ,sum(case when (event_cd = 14 or event_cd = 15) then 1 else 0 end) as BB
from events 
group by 
  year
 ,bat_id
;
