0

当我再插入一行具有相同 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;
4

1 回答 1

1
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;
于 2020-02-26T11:25:24.137 回答