Mysql Compute Two Rows

I have a table like this:

Name: Example

ID | PRICE | MATH 1 | 10.00 | * 1.3 2 | 20.00 | +2 3 | 30.00 | 35% 

Is there any way to calculate / update the PRICE column.

For instance; id 1 looks something like this:

 10 * 1.3 

So:

UPDATE PRICE Example ??? MATHEMATICS? WHERE ID = '1'

Thank you for your time,

+4
source share
2 answers

Is MATH a column in the database containing a free expression that you don't control? It looks like a terrible design.

Without knowing anything about your application and why you want to do such a crazy thing, I would suggest making it at least more obvious and easy to analyze:

 ID | PRICE | COEFFICIENT | ACTION 1 | 10.00 | 1.3 | MULTIPLICATION 2 | 20.00 | 2 | ADDITION 3 | 30.00 | 0.35 | MULTIPLICATION 

Then you can do some IF/ELSE in the database or directly in the server language, but still describe what your use case is ...

+3
source

Poor table design. But if you must use it, you can use a prepared statement to execute a dynamic query. http://dev.mysql.com/doc/refman/5.5/en/sql-syntax-prepared-statements.html

0
source

Source: https://habr.com/ru/post/1482221/


All Articles