Imagine a single column table.
+------+
| v |
+------+
|0.1234|
|0.8923|
|0.5221|
+------+
I want to do the following for line K:
- Take the string K = 1 value: 0.1234
- Indicate how many values in the rest of the table are less than or equal to the value in row 1.
Iterate over all lines. The output should be:
+------+-------+
| v |output |
+------+-------+
|0.1234| 0 |
|0.8923| 2 |
|0.5221| 1 |
+------+-------+
Quick Update I used this approach to compute statistics for each v value in the table above. The cross-join approach was too slow for the size of the data I was dealing with. So, instead, I calculated my stat for a grid of v values, and then matched them with vs in the source data. v_table is the data table from before, and stat_comp is the statistics table.
AS SELECT t1.*
,CASE WHEN v<=1.000000 THEN pr_1
WHEN v<=2.000000 AND v>1.000000 THEN pr_2
FROM v_table AS t1
LEFT OUTER JOIN stat_comp AS t2