You're probably looking for conditionals within your set expressions. This can be achieved with the keyword CASE
:
UPDATE 'database'
SET
a1 = CASE WHEN a1 != 0 THEN (a1 - 1) END,
a2 = CASE WHEN a2 != 0 THEN (a2 - 1) END
WHERE
username='bob';
Be sure to understand the principles of the sql update syntax which consists basically of a single UPDATE ... SET ... [WHERE]
pattern.
Hint: I'm pretty sure your a1,a2,a3,.. fields are of type integer, so - unlike in your code example - the value to check must not put into quotes!