locked
Query for maximum salary of Employee with name, id, Deptname. RRS feed

  • Question

  • User221424154 posted

    Query for maximum salary of Employee with name, id, Deptname.

    Thursday, April 26, 2018 6:53 PM

Answers

  • User-369506445 posted

    also below query  find max for each employee:

     CREATE TABLE #TempTableEmployee(
     ID int,
     Name varchar(20),
     Salary int)
     
    INSERT INTO #TempTableEmployee values(1,'vahid',800)
    INSERT INTO #TempTableEmployee values(1,'vahid',1000)
    INSERT INTO #TempTableEmployee values(2,'jac',50)
    INSERT INTO #TempTableEmployee values(2,'jac',900)
    
    SELECT   Name ,ID  ,MAX(Salary) AS MaxSalary
    FROM #TempTableEmployee 
    GROUP BY    id,name
         

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 26, 2018 7:25 PM

All replies

  • User2053451246 posted

    Without seeing your table structure all we can do is guess.  If this does not work post the create table statement for your table and explain your requirements in more detail.  Your original post is extremely vague.

    SELECT
         t.name
         , t.id
         , t.Deptname
         , MAX(t.Salary) AS MaxSalary
    FROM TableName AS t
    GROUP BY
         t.name
         , t.id
         , t.Deptname

    Thursday, April 26, 2018 7:04 PM
  • User-369506445 posted

    hi

    please try below script:

     CREATE TABLE #TempTable(
     ID int,
     Name varchar(20),
     Salary int)
     
    INSERT INTO #TempTable values(1,'vahid',800)
    INSERT INTO #TempTable values(1,'vahid',1000)
    INSERT INTO #TempTable values(2,'jac',50)
    INSERT INTO #TempTable values(2,'jac',900)
    
    select MAX(salary) from #TempTable where ID=1 and Name='vahid'

    Thursday, April 26, 2018 7:11 PM
  • User-369506445 posted

    also below query  find max for each employee:

     CREATE TABLE #TempTableEmployee(
     ID int,
     Name varchar(20),
     Salary int)
     
    INSERT INTO #TempTableEmployee values(1,'vahid',800)
    INSERT INTO #TempTableEmployee values(1,'vahid',1000)
    INSERT INTO #TempTableEmployee values(2,'jac',50)
    INSERT INTO #TempTableEmployee values(2,'jac',900)
    
    SELECT   Name ,ID  ,MAX(Salary) AS MaxSalary
    FROM #TempTableEmployee 
    GROUP BY    id,name
         

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 26, 2018 7:25 PM