-1

IN SQL (adventureWorks) Database...

I/P :
ALTER PROCEDURE spLessDep
AS
BEGIN
SELECT COUNT(Name) AS COUNT,max(GroupName)
FROM HumanResources.Department
WHERE GroupName <(SELECT MAX(GroupName) FROM HumanResources.Department)
GROUP BY GroupName
ORDER BY COUNT(Name)
END

EXEC spLessDep

O/P:

Name   GroupName

2      Inventory Management
2      Manufacturing
2      Quality Assurance
3      Research and Development
5      Executive General and Administration

Require: I want all minimum values in column(name) by the only statement

jarlh
  • 42,561
  • 8
  • 45
  • 63
BALAJI N
  • 5
  • 2
  • 1
    What is your question here? What isn't working about your attempt? Is it the missing batch separator? – Thom A Aug 13 '21 at 10:17
  • Your question is how to use the `Advertureworks2019` database? That's far too broad a question for [so]. – Thom A Aug 13 '21 at 10:35
  • USE [AdventureWorks2019] ---- Tablename is HumanResource.Department--- i want get all least count of values in Name(column) Based by GroupName(column) ---- dont numeric values on query – BALAJI N Aug 13 '21 at 10:42

1 Answers1

0

I think you are describing TOP (1) WITH TIES:

SELECT TOP (1) WITH TIES COUNT(Name) AS COUNT, GroupName
FROM HumanResources.Department
WHERE GroupName < (SELECT MAX(GroupName) FROM HumanResources.Department)
GROUP BY GroupName
ORDER BY COUNT(Name);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786