0

如何使用 subsonic 编写查询或 lambda 表达式以及以下功能,这些功能可以通过 SQL SERVER 轻松完成

在您的条件中使用 PARTITION 和 RANK

这是我想通过 SubSonic 转换的查询

SELECT * FROM ( SELECT H.location_id.L.item_id AS po_item, H.po_no, H.order_date, H.created_by, RANK() OVER (PARTITION BY H.location_id, L.item_id ORDER BY H.location_id, L.item_id , H.order_date DESC) AS Rank FROM p21_view_po_hdr H INNER JOIN p21_view_po_line L ON H.po_no = L.po_no ) tmp

4

1 回答 1

0

我从以下有用的链接中找到了答案: Converting SQL Rank() to LINQ, or alternative and

http://smehrozalam.wordpress.com/tag/ranking-functions/ 在 LINQ 中,使用 let 关键字可以实现类似的结果。这是一个例子:

1
2
3
4
5
6
7
8

from p in PersonOrders
//where conditions or joins with other tables to be included here
group p by p.PersonID into grp
let MaxOrderDatePerPerson = grp.Max ( g=>g.OrderDate )

from p in grp
where p.OrderDate == MaxOrderDatePerPerson
select p
于 2013-10-24T19:37:40.747 回答