DELETE from wp_users where wp_users.ID not in ( SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user' ) AND wp_users.ID not in ( select distinct(post_author) from wp_posts )
DELETE from wp_users where wp_users.ID not in ( SELECT meta_value FROM wp_postmeta WHERE meta_key = '_customer_user' ) AND wp_users.ID not in ( select distinct(post_author) from wp_posts )
Author: Wojciech Borowicz
I hope this post will help you to do what you need.
In case you want some assistance click here to get in touch