仅显示唯一值

Show Unique values only

我正在使用 SQL Server 2019,并正在寻找一种方法来根据每个 AOC 的最新 FW_Version 仅显示其最新值。这是我到目前为止的查询,但这显示了所有内容:

SELECT DISTINCT
    dbo.Model.ModelName AS AOC,
    dbo.Chipset.Chipset,
    dbo.FormFactor.FormFactor AS Form_Factor,
    dbo.ProductRelease.ECO AS Release,
    dbo.ProductRelease.Date AS Release_Date,
    dbo.Intel.FWVersion AS FW_Version,
    dbo.Intel.ETRACKID
FROM
    dbo.Intel
        INNER JOIN dbo.ProductRelease ON dbo.Intel.ProductReleaseID = dbo.ProductRelease.ID
        INNER JOIN dbo.Model ON dbo.ProductRelease.ModelID = dbo.Model.ID
        INNER JOIN dbo.FormFactor ON dbo.Model.FormFactorID = dbo.FormFactor.ID
        INNER JOIN dbo.Chipset ON dbo.Intel.ControllerID = dbo.Chipset.ControllerID AND dbo.Intel.ChipsetID = dbo.Chipset.ID
ORDER BY 
    dbo.Model.ModelName, 
    dbo.Intel.FWVersion DESC, 
    dbo.ProductRelease.Date DESC

我想只显示黄色标记的项目...我怎样才能做到这一点?

这是我的 Table 的列表,它们是根据相应的 ID

加入的

Table 1: 型号

ID (Primary Key)
ModelName nvarchar(50)
FormFactorID int

Table 2:外形尺寸

ID (Primary Key)
FormFactor nvarchar(15)

Table 3:产品发布

ID (Primary Key)
ModelID int
Date date
ECO nvarchar(10)

Table 4:英特尔

ID (Primary Key)
ProductReleaseID int
ChipsetID int
FWVersion nvarchar(10)
ETRACKID nvarchar(15)

Table 5: 芯片组

ID (Primary Key)
Chipsetnvarchar(20)

一种方法使用 window 函数:

SELECT *
FROM (
    SELECT 
        dbo.Model.ModelName AS AOC,
        dbo.Chipset.Chipset,
        dbo.FormFactor.FormFactor AS Form_Factor,
        dbo.ProductRelease.ECO AS Release,
        dbo.ProductRelease.Date AS Release_Date,
        dbo.Intel.FWVersion AS FW_Version,
        dbo.Intel.ETRACKID,
        ROW_NUMBER() OVER(PARTITION BY dbo.Model.ModelName ORDER BY dbo.ProductRelease.Date DESC) rn
    FROM
        dbo.Intel
        INNER JOIN dbo.ProductRelease ON dbo.Intel.ProductReleaseID = dbo.ProductRelease.ID
        INNER JOIN dbo.Model ON dbo.ProductRelease.ModelID = dbo.Model.ID
        INNER JOIN dbo.FormFactor ON dbo.Model.FormFactorID = dbo.FormFactor.ID
        INNER JOIN dbo.Chipset ON dbo.Intel.ControllerID = dbo.Chipset.ControllerID AND dbo.Intel.ChipsetID = dbo.Chipset.ID
) t
WHERE rn = 1
ORDER BY AOC