I am trying to select rows by given amount volume and order by highest price.
if volume 1.2500 this should select id 2 then 1.(because buyer 2 price higher than 1)
if volume 1.5000 this should select id 2 then 1 finally 3. (when same price like id 1 and 3 lowest id come first)
+--------+------------+-----------+
| id | volume | price |
+--------+------------+-----------+
| 1 | 1.0000 | 14250.00 |
| 2 | 0.2500 | 14251.10 |
| 3 | 0.2500 | 14250.00 |
| 4 | 0.0050 | 14200.00 |
| 5 | 0.5000 | 14200.01 |
+--------+------------+-----------+
$volume= '1.2500';
$q = Buyer::find()
->select(['id','volume','price',])
->where(['volume' => $volume])
->orderBy([
'price'=>SORT_DESC,
'id'=>SORT_ASC
])->all();
expected result like below volume 1.2500
+--------+------------+-----------+
| id | volume | price |
+--------+------------+-----------+
| 2 | 0.2500 | 14251.10 |
| 1 | 1.0000 | 14250.00 |
+--------+------------+-----------+
expected result like below volume 1.5000
+--------+------------+-----------+
| id | volume | price |
+--------+------------+-----------+
| 2 | 0.2500 | 14251.10 |
| 1 | 1.0000 | 14250.00 |
| 3 | 0.2500 | 14250.00 |
+--------+------------+-----------+