• One solution is to sum on a conditional expression like so:

    select employeeid, historyid,

    sum(case when activitytype = 'OPEN' then 1 else 0 end) Opens,

    sum(case when activitytype = 'CLICK' then 1 else 0 end) Clicks

    from tablename

    group by employeeid, historyid;

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho