MySQL:错误代码:#1242 - 子查询 returns 多于 1 行
MySQL: Error code : #1242 - Subquery returns more than 1 row
当我再插入一行相同的 lc_number 时显示此错误,我该如何解决。
此处的错误消息:
SELECT
x.lc_number,
x.Destination,
x.Allotment,
x.Total_Bags,
x.Empty_Bags,
y.Delivered_Qty,
y.Sent_Qty,
y.challan_no,
y.Date,
COALESCE (x.Allotment - (SELECT r.Delivered_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number), x.Allotment) AS Balance_m_ton,
COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number), x.Total_Bags) AS Balance_bags,
COALESCE (x.Empty_Bags + COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number), x.Total_Bags), x.Empty_Bags) AS Empty_Bags
FROM
badc_allocations as x,
delivery_point AS y
WHERE
x.lc_number = y.lc_number;
SELECT
x.lc_number,
x.Destination,
x.Allotment,
x.Total_Bags,
x.Empty_Bags,
y.Delivered_Qty,
y.Sent_Qty,
y.challan_no,
y.Date,
COALESCE (x.Allotment - (SELECT r.Delivered_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number LIMIT 1), x.Allotment) AS Balance_m_ton,
COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number LIMIT 1), x.Total_Bags) AS Balance_bags,
COALESCE (x.Empty_Bags + COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number LIMIT 1), x.Total_Bags), x.Empty_Bags) AS Empty_Bags
FROM
badc_allocations as x,
delivery_point AS y
WHERE
x.lc_number = y.lc_number;
当我再插入一行相同的 lc_number 时显示此错误,我该如何解决。 此处的错误消息:
SELECT
x.lc_number,
x.Destination,
x.Allotment,
x.Total_Bags,
x.Empty_Bags,
y.Delivered_Qty,
y.Sent_Qty,
y.challan_no,
y.Date,
COALESCE (x.Allotment - (SELECT r.Delivered_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number), x.Allotment) AS Balance_m_ton,
COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number), x.Total_Bags) AS Balance_bags,
COALESCE (x.Empty_Bags + COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number), x.Total_Bags), x.Empty_Bags) AS Empty_Bags
FROM
badc_allocations as x,
delivery_point AS y
WHERE
x.lc_number = y.lc_number;
SELECT
x.lc_number,
x.Destination,
x.Allotment,
x.Total_Bags,
x.Empty_Bags,
y.Delivered_Qty,
y.Sent_Qty,
y.challan_no,
y.Date,
COALESCE (x.Allotment - (SELECT r.Delivered_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number LIMIT 1), x.Allotment) AS Balance_m_ton,
COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number LIMIT 1), x.Total_Bags) AS Balance_bags,
COALESCE (x.Empty_Bags + COALESCE (x.Total_Bags - (SELECT r.Sent_Qty FROM delivery_point AS r WHERE x.lc_number = r.lc_number LIMIT 1), x.Total_Bags), x.Empty_Bags) AS Empty_Bags
FROM
badc_allocations as x,
delivery_point AS y
WHERE
x.lc_number = y.lc_number;