Ciao,
proverei cosi,

select SUM(distinct(p)) from table where p = GET['a'];

E' assolutamente da provare

Ciao