SELECT * FROM [dbo].[test1] AS A
OUTER APPLY (
SELECT TOP 1 *
FROM [dbo].[test1]
WHERE (N'abc' = [company])
AND A.[Value] = 'TEST'
ORDER BY UpdateTime DESC
) AS B
@listennn08 感謝回覆,但真的不知道怎麼合起來寫?
以下為例,應該怎麼在各自的join 下加上order by 和top 1的處理?
var categorizedProducts = product
.Join(productcategory, p => p.Id, pc => pc.ProdId, (p, pc) => new { p, pc })
.Join(category, ppc => ppc.pc.CatId, c => c.Id, (ppc, c) => new { ppc, c })
.Select(m => new {
ProdId = m.ppc.p.Id, // or m.ppc.pc.ProdId
CatId = m.c.CatId
// other assignments
});
我沒有測試過
從上面兩篇推論出來的程式
var categorizedProducts =
from p in product
join pc in productcategory on p.Id equals pc.ProdId
join c in category on pc.CatId equals c.Id
select new {
p.Id, // or pc.ProdId
c.CatId,
pc.ProdId.OrderByDescending().First(),
c.CatId.OrderByDescending().First()
// other assignments
};