Home > OS >  SQL script can sum the digits of a number
SQL script can sum the digits of a number

Time:01-18

I created a table with a column containing numbers listed from 1 to 100. I want to delete numbers that divide by 3 without any remainder. Who can recommend me a way (script) to do that. Only logic I could make in this problem is that if the sum of digits of a number can divide by 3 that means any number which correspond to that case could be divisible.

CodePudding user response:

If you are looking to delete the rows with number divisible completely by 3, you can use built-in modulus function

You could say something like this

delete
from myTable
where colNumber%3 = 0

CodePudding user response:

This query should solve your problem

DELETE FROM table WHERE (id % 3) = 0;
  •  Tags:  
  • Related