magento2 – How to assign customer orders to registered customers by email via SQL?


I use this SQL below to manually assign guest commands to registered users.

UPDATE sales_order SET customer_id = {YOUR CUSTOMER ID}, customer_is_guest = 0 where entity_id = {YOUR ORDER ID};
UPDATE sales_order_grid SET customer_id = {YOUR CUSTOMER ID} where entity_id = {YOUR ORDER ID};
UPDATE downloadable_link_purchased SET customer_id = {YOUR CUSTOMER ID} WHERE order_id = {YOUR ORDER ID};

How can I automatically assign by email each order placed by guest users to registered customers?