我试图在两个表中为一些完整性编写一些查询.查询是这样的
SELECT if( o.is_discounted !=1, o.item_cost, o.discounted_item_cost ) AS order_item_total,
SUM( oi.quantity * oi.price ) AS item_total
FROM orders o
INNER JOIN order_items oi ON oi.order_id = o.id
WHERE order_item_total != item_total
GROUP BY o.id
我过去肯定会在这些列中使用别名,所以我不确定为什么在这种情况下它告诉我order_item_total不是列.
在聚合列上使用.
SELECT if(o.is_discounted != 1, o.item_cost, o.discounted_item_cost) order_item_total,
  SUM(oi.quantity * oi.price) item_total
FROM orders o
INNER JOIN order_items oi ON oi.order_id = o.id
GROUP BY o.id
HAVING order_item_total != item_total
| 归档时间: | 
 | 
| 查看次数: | 5251 次 | 
| 最近记录: |