• Is REF_DOC a unique value? Or do you have it several times in ztb_Carrier_Delivery_Metrics?

    As I see it, this is a problem with your data.

    EDIT: Could you show us your code and sample data to be sure?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2