select t.a,t.b,(select s.c from table1 s where t.id=s.tid) as c, sum(t.sal) from table t 如何分组

2025-04-15 12:40:36
推荐回答(1个)
回答1:

最简单的直接把 as c 这段拿到外面再套一层查询

select t.a,t.b,t.c,(select s.c from table1 s where t.id=s.tid) from (
select t.a,t.b,sum(t.sal) as c,max(t.id) as id from table t group by a,b) t