I have a table where a column (COL1) can have values from 0 to 1 (inclusive). From this column I would like to create a new column that categorizes COL1 using predefined ranges (i.e. create bins). When the number of categories / bins is small, this can easily be done using CASE WHEN, for example:
SELECT
CASE WHEN COL1 <= 0.2 THEN 1
WHEN COL1 > 0.2 AND COL1 <= 0.4 THEN 2
....
WHEN COL1 > 0.8 AND COL1 <= 1 THEN 5
END AS COL1_bin
FROM Table
Since I would like to have 100 bins, I am looking for a way to do this more 'automatically' using a function, where I can for example give a minimum, maximum and stepsize / binsize (e.g., min = 0, max = 1, stepsize = 0.01)
I am doing this in HiveQL, which is supposed to be very similar to MySQL.