Aracılığıyla paylaş


MIN (Transact-sql)

İfade içindeki en küçük değeri verir. Tarafından takip edilmesi yan tümcesi içinde.

Konu bağlantısı simgesi Transact-SQL Sözdizim Kuralları

Sözdizimi

MIN ( [ ALL | DISTINCT ] expression ) 

Bağımsız değişkenler

  • ALL
    Toplama işlevi, tüm değerleri için geçerlidir. TÜM varsayılan olduğunu.

  • FARKLI
    Her benzersiz bir değer kabul eden belirtir. DISTINCT MIN ile anlamlı değildir ve sadece ISO uyumluluğu için kullanılabilir.

  • expression
    Bir sabit, sütun adı veya işlev ve aritmetik, bitwise ve dizge işleçleri herhangi bir birleşimi olduğunu. MIN ile kullanılabilir numeric, char, varchar, uniqueidentifier, ya datetimesütunlar, ama değil bitsütun. Toplama işlevleri ve alt sorgular verilmez.

    Daha fazla bilgi için, bkz. Ifadeler (Transact-sql).

Dönüş Türleri

Bir değer döndüren aynı expression.

Açıklamalar

MIN herhangi bir boş değerleri yoksayar.

Karakter veri sütunları ile MIN sıralama sırası en küçük değeri bulur.

Örnekler

A.Basit bir örnek

Aşağıdaki örnek en düşük (en az) vergi oranını verir.

USE AdventureWorks2012;
GO
SELECT MIN(TaxRate)
FROM Sales.SalesTaxRate;
GO

USE AdventureWorks2012;
GO
SELECT MIN(TaxRate)
FROM Sales.SalesTaxRate;
GO

Sonuç kümesi buradadır.

-------------------

5.00

(1 row(s) affected)

B.ÜZERINDEN yan tümcesi kullanarak

MIN, max, avg ve count işlevler ÜZERINDEN yan tümcesi ile her bir bölüm için toplanmış değerlerini sağlamak için aşağıdaki örnek kullanır HumanResources.Departmenttablosu.

USE AdventureWorks2012; 
GO
SELECT DISTINCT Name
       , MIN(Rate) OVER (PARTITION BY edh.DepartmentID) AS MinSalary
       , MAX(Rate) OVER (PARTITION BY edh.DepartmentID) AS MaxSalary
       , AVG(Rate) OVER (PARTITION BY edh.DepartmentID) AS AvgSalary
       ,COUNT(edh.BusinessEntityID) OVER (PARTITION BY edh.DepartmentID) AS EmployeesPerDept
FROM HumanResources.EmployeePayHistory AS eph
JOIN HumanResources.EmployeeDepartmentHistory AS edh
     ON eph.BusinessEntityID = edh.BusinessEntityID
JOIN HumanResources.Department AS d
 ON d.DepartmentID = edh.DepartmentID
WHERE edh.EndDate IS NULL
ORDER BY Name;

USE AdventureWorks2012; 
GO
SELECT DISTINCT Name
       , MIN(Rate) OVER (PARTITION BY edh.DepartmentID) AS MinSalary
       , MAX(Rate) OVER (PARTITION BY edh.DepartmentID) AS MaxSalary
       , AVG(Rate) OVER (PARTITION BY edh.DepartmentID) AS AvgSalary
       ,COUNT(edh.BusinessEntityID) OVER (PARTITION BY edh.DepartmentID) AS EmployeesPerDept
FROM HumanResources.EmployeePayHistory AS eph
JOIN HumanResources.EmployeeDepartmentHistory AS edh
     ON eph.BusinessEntityID = edh.BusinessEntityID
JOIN HumanResources.Department AS d
 ON d.DepartmentID = edh.DepartmentID
WHERE edh.EndDate IS NULL
ORDER BY Name;

Sonuç kümesi buradadır.

Name                          MinSalary             MaxSalary             AvgSalary             EmployeesPerDept
----------------------------- --------------------- --------------------- --------------------- ----------------
Document Control              10.25                 17.7885               14.3884               5
Engineering                   32.6923               63.4615               40.1442               6
Executive                     39.06                 125.50                68.3034               4
Facilities and Maintenance    9.25                  24.0385               13.0316               7
Finance                       13.4615               43.2692               23.935                10
Human Resources               13.9423               27.1394               18.0248               6
Information Services          27.4038               50.4808               34.1586               10
Marketing                     13.4615               37.50                 18.4318               11
Production                    6.50                  84.1346               13.5537               195
Production Control            8.62                  24.5192               16.7746               8
Purchasing                    9.86                  30.00                 18.0202               14
Quality Assurance             10.5769               28.8462               15.4647               6
Research and Development      40.8654               50.4808               43.6731               4
Sales                         23.0769               72.1154               29.9719               18
Shipping and Receiving        9.00                  19.2308               10.8718               6
Tool Design                   8.62                  29.8462               23.5054               6

 (16 row(s) affected)

Name                          MinSalary             MaxSalary             AvgSalary             EmployeesPerDept
----------------------------- --------------------- --------------------- --------------------- ----------------
Document Control              10.25                 17.7885               14.3884               5
Engineering                   32.6923               63.4615               40.1442               6
Executive                     39.06                 125.50                68.3034               4
Facilities and Maintenance    9.25                  24.0385               13.0316               7
Finance                       13.4615               43.2692               23.935                10
Human Resources               13.9423               27.1394               18.0248               6
Information Services          27.4038               50.4808               34.1586               10
Marketing                     13.4615               37.50                 18.4318               11
Production                    6.50                  84.1346               13.5537               195
Production Control            8.62                  24.5192               16.7746               8
Purchasing                    9.86                  30.00                 18.0202               14
Quality Assurance             10.5769               28.8462               15.4647               6
Research and Development      40.8654               50.4808               43.6731               4
Sales                         23.0769               72.1154               29.9719               18
Shipping and Receiving        9.00                  19.2308               10.8718               6
Tool Design                   8.62                  29.8462               23.5054               6

 (16 row(s) affected)

Ayrıca bkz.

Başvuru

Toplama işlevleri (Transact-sql)

MAX (Transact-sql)

Yan (Transact-sql)