I'm afraid this is beyond what I can effectively do on this forum. I'd suggest a premier support ticket to look into this and help you write the proper SQL statement. I'm not even sure where and how this is all used or how it fits into your site... there is just too much custom research necessary to do effectively here.