2011-12-09 72 views
0

我如何使用亞音速具有以下功能,這很容易通過SQL Server如何使用分區,RANK功能通過亞音速

做你的標準使用分區和RANK編寫查詢或lambda表達式

下面是我想通過亞音速

SELECT *轉換來源 ( SELECT H.location_id。L.item_id AS po_item查詢,H.po_no,H.order_date,H.created_by, RANK() OV ER(PARTITION BY H.location_id,L.item_id ORDER BY H.location_id,L.item_id,H.order_date DESC)AS排名 FROM p21_view_po_hdrħINNER JOIN p21_view_po_line大號 ON H.po_no = L.po_no )TMP

+0

什麼亞音速做的是,創建一個SQL代碼,從一個強類型的變量,以避免在發展中的錯誤,並使其更容易編寫SQL代碼。但是,如果你知道你在sql上做了什麼,保持原樣,並使用亞音速的直接sql命令。 – Aristos

+0

目前我無法在亞音速中找到分區和排序功能。 –

回答

0

我發現從下面有用的鏈接答案: 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