仅显示每场比赛的第一行
我有一个表(AreaPartners),我只想匹配每个组中的第一个“名称”记录,按“ID”排序,按“区域”分组。因此,对于下表:
Area Name ID
AB ISmith 748
AB AWood 750
AB HArcher 751
AB DMunslow 753
AB DCornelius 754
BH MLee 301
BH NMcClean 307
BH DMiles 309
BH LPayze 325
BH MPinnock 329
我想返回 AB 的 ISmith 和 BH 的 MLee 结果。
我该怎么做呢?我相信这与 Group By 功能有关,但我一生都无法让它发挥作用。
I have a table (AreaPartners), and I want to match only the first "Name" record in each group, order by "ID", grouped by "Area". So for the table below:
Area Name ID
AB ISmith 748
AB AWood 750
AB HArcher 751
AB DMunslow 753
AB DCornelius 754
BH MLee 301
BH NMcClean 307
BH DMiles 309
BH LPayze 325
BH MPinnock 329
I'd want to return the results ISmith for AB and MLee for BH.
How do I go about doing this? I believe it's something to do with the Group By function, but I can't for the life of me get it to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
由于注释而更新(没有表变量并且分区不是 MS access 语句)。您还可以使用
IN
语句来完成此操作:在 MSSQL 中,您可以这样写:
Update because of comment (There is no table variable and Partition over is not a MS access statement). You can also do it with an
IN
statement:In MSSQL you can write this: