'How to dynamic calculate value using formulas in postgresql
I'm in new this field. How do I manage the dynamic calculation with formulas and what steps to achieve the below output?.
I have tables.
Table 1 - Info_question table is for details about questions name and id.
q_id | questions_name |
---|---|
1 | A |
2 | B |
3 | C |
4 | D |
Table 2 - data_question is for data values.
id | q_id | period | data_value |
---|---|---|---|
1 | 1 | 2022 | 1000 |
2 | 1 | 2021 | 2000 |
3 | 2 | 2022 | 3000 |
4 | 3 | 2022 | 4000 |
5 | 4 | 2022 | 5000 |
I need to calculate A+B+C and that output will insert into data_question table and new question will create in the info_question table.(formulas will change for new question like A/B*100 or A+C and question id will be new generate)
For (A+B+C) Output should be shows like below tables.
data_question table
id | q_id | period | data_value |
---|---|---|---|
1 | 1 | 2022 | 1000 |
2 | 1 | 2021 | 2000 |
3 | 2 | 2022 | 3000 |
4 | 3 | 2022 | 4000 |
5 | 4 | 2022 | 5000 |
6 | 5 | 2022 | 8000 |
7 | 5 | 2021 | 2000 |
and info_question
q_id | questions_name |
---|---|
1 | A |
2 | B |
3 | C |
4 | D |
5 | E |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|