Skip to content
Advertisement

SQL – Delete random rows where sum is equal to given number

I want to get some random rows from the given table where the sum is 250(this can be changed). I don`t need to 100% accurate but can be approximate. Like for 250 (1,5,7)

Note:- My table has huge data.

Advertisement

Answer

For any specific numbers, you can return the closest sum using logic with joins. For instance for 3 numbers — as in your example:

Note that fetch first is standard SQL. Some databases spell it differently, for instance as limit or select top.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement