0

我正在尝试做这样的事情,所以结果是 2 个单独选择的组合

SELECT
order_number,placed_by,placed_when,updated_by,updated_when,
(SELECT SUM(qty_order<>qty_rec) 
 FROM 1_purchase_orders 
 WHERE order_number=order_number AND line_number<>0)
WHERE
supp_number=4 AND line_number=0;
4

1 回答 1

1

您在查询中使用的相关子查询必须只返回一个标量值。像这样的东西:

SELECT 
  t1.order_number,
  t1.placed_by,
  t1.placed_when,
  t1.updated_by,
  t1.updated_when, 
  (SELECT SUM(t2.qty_order <> t2.qty_rec) 
   FROM 1_purchase_orders t2
   WHERE t2.order_number = t1.order_number AND t2.line_number <> 0 
   ORDER BY qty_order LIMIT 1) 
FROM 1_purchase_orders t1
WHERE t1.supp_number = 4 AND t1.line_number=0;
于 2012-11-19T13:40:16.490 回答