我有一张桌子,上面有以下内容:
+----+-------+-------+-----------+-----------+--------------+--------------+
| id | stock | price | usedStock | usedPrice | specialStock | specialPrice |
+----+-------+-------+-----------+-----------+--------------+--------------+
| #1 | 1 | 10.00 | 0 | 0 | 0 | 0 |
| #2 | 0 | 0 | 1 | 15.00 | 1 | 20.00 |
| #3 | 0 | 0 | 0 | 11.00 | 1 | 14.00 |
+----+-------+-------+-----------+-----------+--------------+--------------+
如果商品类型有库存,我想创建一个查询,首先按最低价格订购。
因此查询将产生以下顺序:
#1 - 10.00 (because 10.00 is the lowest result)
#3 - 14.00 (because although 11.00 is less, it's not in stock)
#2 - 15.00 (because 15.00 is lower than 20.00)
我已经在这个问题中添加了 PHP 标记,以防在选择表格后使用 PHP 进行更快的计算。