SELECT 
    COALESCE(c.sActual_Dest_ID, 'N/A') AS Lane,
    COALESCE(c.Total_rate, 0) AS Total_rate,
    COALESCE(c.DestFull_rate, 0) AS DestFull_rate
FROM (SELECT 1) AS p
LEFT JOIN (
    SELECT 
        sActual_Dest_ID,
        CASE 
            WHEN TIMESTAMPDIFF(SECOND, :starttime, :endtime) = 0 THEN 0
            ELSE ROUND(COUNT(*) * 3600.0 / TIMESTAMPDIFF(SECOND, :starttime, :endtime), 2)
        END AS Total_rate,
        CASE 
            WHEN TIMESTAMPDIFF(SECOND, :starttime, :endtime) = 0 THEN 0
            ELSE ROUND(SUM(CASE WHEN adiSort_Code_0 = 5 THEN 1 ELSE 0 END) * 3600.0 / TIMESTAMPDIFF(SECOND, :starttime, :endtime), 2)
        END AS DestFull_rate
    FROM item_data
    WHERE t_stamp BETWEEN :starttime AND :endtime
        AND (sActual_Dest_ID LIKE CONCAT(:lane, '%') OR :lane IS NULL OR :lane = '')
    GROUP BY sActual_Dest_ID
) AS c ON 1=1
ORDER BY c.sActual_Dest_ID;
