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 19, 2016, 10:16 PM EDT
Thanks Subash
Pramod ThakurPosted Sep 19, 2016, 10:16 PM EDT
Thanks Kiran Thakur
SubashPosted Sep 19, 2016, 3:51 AM EDT
Good
Kiran ThakurPosted Jan 16, 2016, 12:35 AM EST
thanks for sharing
Ebrahim MoharramiPosted Dec 25, 2014, 8:19 AM EST
Very simple mental