I want to change the number added by the conditions within SQL.

Asked 1 years ago, Updated 1 years ago, 42 views

Currently, we are adding the total number of pvs.id to the product.price as shown below.
Below is
+1 for Product.price when pvs.id total is 10,
+2 for Product.price when pvs.id total is 20,
+3 for Product.price when pvs.id total is 30,
...
+10 for Product.price when pvs.id totals 100,

I'd like to add it one by one, but is it possible to write it in SQL?
Also, if possible, what kind of code would it be?

Model/Product.php

public$virtualFields=array(
        'product_price' = >'
                Product.price+(10*(SELECT COALESCE(COUNT(pvs.id), 0) FROM pvs WHERE product_id=Product.id))
        )',
    );

php cakephp sql

2022-09-30 16:48

1 Answers

public$virtualFields=array(
    'product_price' = >'
            Product.price+(SELECT COALESCE(COUNT(pvs.id), 0) FROM pvs WHERE product_id=Product.id)/10)
    )',
);

resolved in .


2022-09-30 16:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.