问一句sql怎么写
表1
ID Name Count
1 aa 20
2 aa 30
3 bb 20
4 cc 40
表2
ID Name
1 aa
2 bb
查询表2对应表1最大count结果集
结果为
aa 30
bb 20
请问怎么写?
------解决方案--------------------select a.name,Count=max(a.count)
from 表1 a inner join 表2 b
on a.name=b.name
group by a.name
order by a.name
------解决方案--------------------select a.Name,(select max(Count) from 表1 where name=a.name)[count] from 表2 a
------解决方案-------------------- Select
B.Name,
Max(A.[Count]) As [Count]
From
表2 B
Inner Join
表1 A
On A.Name = B.Name
Group By B.Name