Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

mysql - Unselected value from a group by query to subquery

I have to provide an unselected set of values from a group by query to a subquery

Like

col_1 col_2 col_3
1 a 154
2 a 845
3 b 558
4 c 88

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your approach is wrong simply join the tables and aggregate the values

select col2,sum(balance) 
from tb_1
join accounts a on a.id = tb_1.col3
group by col2;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...