c# – LINQ join和group

前端之家收集整理的这篇文章主要介绍了c# – LINQ join和group前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是LINQ的新手,我正在尝试将此SQL查询转换为其LINQ等效项:
select S.*
from Singles S
join (
    select max(SingleId) as SingleId
    from Single 
    group by ArtistId) S2 on S2.SingleId = S.SingleId
order by Released desc

该表如下所示:

-----------
| Singles   |
|-----------|
| SingleID  |
| ArtistId  |
| Released  |
| Title     |
| .....     |
 -----------

等等…
并包含例如这些项目:

SingleID   ArtistID    Released    Title
1          1           2011-05-10  Title1
2          1           2011-05-10  Title2
3          2           2011-05-10  Title3
4          3           2011-05-10  Title4
5          4           2011-05-10  Title5
6          2           2011-05-10  Title6
7          3           2011-05-10  Title7
8          5           2011-05-10  Title8
9          6           2011-05-10  Title9

所以我想要获得最新的单曲,但每个艺术家只有一个.谁能帮助我? 原文链接:https://www.f2er.com/csharp/100609.html

猜你在找的C#相关文章