Skip to content
Advertisement

Redshift – Breaking number into 10 parts and finding which part does a number fall into

I am trying to break down a given number into 10 equal parts and then compare a row of numbers and see in which of the 10 parts they fall under.

ref_number, number_to_check
70, 34
70, 44
70, 14
70, 24

In the above data set, I would like to break 70 into 10 equal parts (in this case it would be 7,14,21, and so on till 70). Next I would like to see in which “part” does the value in column “number_to_check” fall into.

Output expected:

ref_number, number_to_check, part
70, 34, 5
70, 44, 7
70, 14, 2
70, 24, 4

Advertisement

Answer

You want arithmetic. If I understand correctly:

select ceiling(number_to_check * 10.0 / ref_number)

Here is a db<>fiddle (the fiddle happens to use Postgres).

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