Let’s first create a table with four fields.
- CREATE TABLE [dbo].[table1](
- [id] [int] NULL,
- [Name] [varchar](30) NULL,
- [Salary] [int] NULL,
- [DepId] [int] NULL
- )
- INSERT table1 VALUES (1, 'test1', 1200, 1)
- INSERT table1 VALUES (2, 'test2', 1500, 1)
- INSERT table1 VALUES (3, 'test3', 1300, 2)
- INSERT table1 VALUES (4, 'test4', 2000, 3)
- INSERT table1 VALUES (5, 'test5', 1000, 2)
- INSERT table1 VALUES (6, 'test6', 1300, 2)
- INSERT table1 VALUES (1, 'test1', 1200, 1), (2, 'test2', 1500, 1),(3, 'test3', 1300, 2),(4, 'test4', 2000, 3),(5, 'test5', 1000, 2),(6, 'test6', 1300, 2)
- select * from table1

Now write a query for the min and max salary by department:
- select depid, max(salary) as MaxSalary, min(Salary) as MinSalary from table1 group by DepId

I hope you enjoy this article.
Happy coding.

Pramod ThakurPosted Sep 20, 2016, 2:16 AM
Thanks Subash
Pramod ThakurPosted Sep 20, 2016, 2:16 AM
Thanks Kiran Thakur
SubashPosted Sep 19, 2016, 7:51 AM
Good
Kiran ThakurPosted Jan 16, 2016, 5:35 AM
thanks for sharing
Ebrahim MoharramiPosted Dec 25, 2014, 1:19 PM
Very simple mental