mysql - Need Optimized Query which take data from three tables -
three tables
accounts, products, users
- select users id , email users table there id in accounts
then filter them out products table user bought more 3 products (need count users in product table , exclude user if count more 3).
select id, email users id in ( select user_id accounts users.id = user_id )
i got users id , emails, need filter them out product table. in product table have 'product_id' , 'leader_id', user id.
i need optimized query, because tables big
i understand bit...something should works:
select u.id,u.mail, (select count(1) products products.leader_id = u.id) conteo user u left join account ac on(u.id = ac.user_id) having (conteo>3)
i hope helps ;)
saludos.
Comments
Post a Comment