I
I
ilysion_in_life2018-11-15 09:39:35
MySQL
ilysion_in_life, 2018-11-15 09:39:35

How to correctly formulate a query to the database or maybe there is a better solution?

Hello everyone, guys, tell me how to formulate the request correctly, I make cumulative discounts and here is the request

$queryResults = Yii::app()->db->createCommand()->
        select( '*' )->
        from('DiscountRegular')->
        where('active = "1" AND start_date <= CURRENT_TIMESTAMP() AND end_date >= CURRENT_TIMESTAMP() AND price >= '.$regular_discount.'')->
        queryAll();

i have two discounts for example discount when user reach purchases by 1000 and by 2000
$regular_discount variable contains value for example 2000 in condition i use condition
that if value in variable and price column are equal or value of variable is greater then true
but problem is that if the value is less than, for example, 1999, then it is neither equal nor greater
and does not find records with a discount of 1000, I need to do something like that, if the specified value
in the price (2000) column is not reached, and for example, 1999, then what would be used record with a discount of 1000

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xtress, 2018-11-15
@xtress

Try to swap if the base allows it (tested on the muscle - it allows):

$queryResults = Yii::app()->db->createCommand()->
        select( '*' )->
        from('DiscountRegular')->
        where('active = "1" AND start_date <= CURRENT_TIMESTAMP() AND end_date >= CURRENT_TIMESTAMP() AND ' . $regular_discount . ' >= price')->
        queryAll();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question