Mysql Select Group By获取字段子表的最后记录的最后一个

时间:2019-04-13 07:15:49

标签: mysql

这是问题。有2个主要表制造商(M)和sub_locations(SL)。 sub_locations 是父级表具有子表 batch_bundle_serial_codes ,batch_bundle_serial_codes子表具有制造

sub_locations->batch_bundle_serial_codes->manufactures

我想基于batch_bundle_serial_codes获取数据。我想要它的最后一个位置在制成品表中。 我不能使用min或max。在mysql中是否有LAST函数。

SELECT      
        BBSC.id,
        M.location_id,           
        SUM(M.amount) AS amount,
        SL.id,        
        SL.name
    FROM
        manufactures M
        INNER JOIN manufacture_order_nodes MON ON MON.id = M.manufacture_order_node_id
        INNER JOIN product_operations PO ON PO.id = M.product_operation_id
        INNER JOIN batch_bundle_serial_codes BBSC ON BBSC.id = M.batch_bundle_serial_code_id                    
        LEFT JOIN sub_locations SL ON SL.id = BBSC.sub_location_id          
    GROUP BY 
        BBSC.id
    ORDER BY
        BBSC.id
    ;

0 个答案:

没有答案
相关问题