【问题标题】:How can I use PARTITION and RANK functionality through SubSonic如何通过 SubSonic 使用 PARTITION 和 RANK 功能
【发布时间】:2011-12-09 20:52:20
【问题描述】:

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

在您的条件中使用 PARTITION 和 RANK

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

选择 * 从 ( 选择 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 内部连接 ​​p21_view_po_line L ON H.po_no = L.po_no ) 时间

【问题讨论】:

  • subsonic所做的就是创建一个sql代码,从强类型变量中避免开发中的错误,让编写sql代码更容易。但是如果你知道你在 sql 上做了什么,保持 sql 原样并使用 subsonic 的直接 sql 命令。
  • 目前我在亚音速中找不到 Partition 和 Rank 函数。

标签: subsonic rank database-partitioning


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-05-14
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    相关资源
    最近更新 更多