Fastest way to find Quotient by Dividing two Number
What you want to do is pretty much the definition of "modulo arithmetic". If the built-in arithmetic in your database can't do the calculation fast enough, I'm not sure what you could do to improve that short of writing your own database engine or buying higher-powered hardware.
Is the problem really the speed of the arithmetic, or is it record retrieval or indexing? I mean, if you're saying something like:
select ... whatever ... from table1 join table2 using (someid)where (table1.q / table2.d) % 10 = 4
and you don't have an index on the function (table1.q / table2.d ) % 10, this would require the db to read every record, perform the calculation, and then pick out those that give the right answer. Your problem might not be arithmetic, but indexing.