VB.net 指定条件,取日期最大、最小值的记录问题 SQL + LINQ
SqlServer:
DECLARE @CustomerGUID AS uniqueidentifier='23737252-B51C-40A9-AA27-3436BFFA3926' ; With CTE_IDMaxDT AS ( SELECT [MaterialID] ,MAX([DTPoint]) AS MaxDT FROM [Quotation] WHERE [QuotationTypeID]=1 AND [CustomerGUID]=@CustomerGUID GROUP BY [MaterialID] ) SELECT [ID] ,[CustomerGUID] ,[DTPoint] ,[DTCreate] ,[DTUpdate] FROM [Quotation] inner JOIN [CTE_IDMaxDT] ON [Quotation].[MaterialID]=[CTE_IDMaxDT].[MaterialID] AND [Quotation].[DTPoint]=[CTE_IDMaxDT].[MaxDT] WHERE [QuotationTypeID]=1 AND [CustomerGUID]=@CustomerGUID ORDER BY [Quotation].[MaterialID]
VB.Net LINQ
Dim Query = From x As Class_Quotation In LinqList Group By x.MaterialID, x.QuotationTypeID, x.PriceUnit, x.VehicleTypeID Into g = Max(x.DTPoint) Dim QueryJoin = From x In Query Join y In LinqList On x.MaterialID Equals y.MaterialID And x.QuotationTypeID Equals y.QuotationTypeID And x.PriceUnit Equals y.PriceUnit And x.VehicleTypeID Equals y.VehicleTypeID And x.g.Date Equals y.DTPoint