The query seems a little off, you should try with it setup like this instead:
SELECT table.inventory
FROM table
WHERE (table.inventory - colname) > 0
For the runtime value of the colname parameter you should use the bindings to select the quantity field from the add to cart form.