代码之家  ›  专栏  ›  技术社区  ›  mark smith

在SQL Server的子查询中获取最小价格(使用DISTINCT)?

  •  0
  • mark smith  · 技术社区  · 16 年前

    MIN(销售价格)、型号、品牌

    2 回复  |  直到 16 年前
        1
  •  3
  •   Philippe Leybaert    16 年前

    你需要添加一个GROUP BY子句并去掉DISTINCT:

    SELECT 
           datepart(year,[Registration]) AS YearRegistered, 
           MIN(SalePrice), Model, Make
    FROM 
           [VehicleSales] 
    GROUP BY 
           datepart(year,[Registration]), Model, Make
    
        2
  •  1
  •   Quassnoi    16 年前
    SELECT  DATEPART(year,[Registration]) AS YearRegistered, Model, Make, MIN(SalePrice)
    FROM    [VehicleSales]
    GROUP BY
            DATEPART(year,[Registration]) AS YearRegistered, Model, Make