Answer the question
In order to leave comments, you need to log in
How can I calculate the "cost" of different combinations of fields in a table with one query?
There is a table with fields:
| task | user | formula_1_cost | formula_1_cost | formula_1_cost |
|------ |------ |---------------- |---------------- |---------------- |
| 1 | 1 | 5 | 5 | 25 |
| 1 | 2 | 0 | 0 | 26 |
| 1 | 3 | 23 | 0 | 4 |
Answer the question
In order to leave comments, you need to log in
SELECT
CASE WHEN <condition> THEN <formula1> ELSE <formula2> END
...
If "formulas" are a countable number and they are known in advance - then case from Ivan 's variant
's variant
Otherwise - expand unpivot/pivot and get some expanded multidimensionality, where one dimension is a user, the second is a parameter, the third is a derivative of the formula identifier...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question