適正なインデックスがあれば特にスピードは変わらないと思いますが?
//元データ
create table user(user_id int,user_name varchar(20),index(user_id,user_name));
insert into user values(1,'aaa'),(2,'bbb'),(3,'ccc');
create table user_agreements(user_id int ,money int,index(user_id,money));
insert into user_agreements values(1,5000),(2,3000),(2,5000),(1,8000),(2,4500),(3,10000),(3,2500);
//例1
select user_id,count(money) as money,user_name
from user
inner join user_agreements using(user_id)
group by user_id;
//例2
select user_id,(select count(money) as money from user_agreements where user_id=t1.user_id) as money,user_name
from user as t1;
//例3
select user_id, money,user_name
from user as t1
inner join (select user_id,count(money) as money from user_agreements group by user_id) as t2
using(user_id);
例1と例2はほぼ同じ、例3は若干効率が悪いかもしれません
お礼
ありがとうございます! 帰り次第3パターン試してみようと思います 色々教えてくださり、本当にありがとうございました