在SQL中找到各部门员工的最高薪水

时间:2018-10-23 10:01:37

标签: sql

enter image description here

结果应为下图中的下划线行 enter image description here

3 个答案:

答案 0 :(得分:2)

您可以使用相关子查询

select * from tablename t1 where salary = 
(select max(salary) from tablename t2 where t1.deptname=t2.deptname)

答案 1 :(得分:1)

如果支持您的dbms,请使用窗口功能

select * from 
(
select *, row_number() over(partition by department order sal desc) rn
from your_tab
) t where t.rn=1

答案 2 :(得分:0)

const User = require("../db").user;
const LocalStrategy = require("passport-local").Strategy;

module.exports = function(passport) {

    passport.serializeUser(function(user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function(id, done) {
        User.findOne({where:{id:id}})
    });

    passport.use(new LocalStrategy(
            {
                passReqToCallback: true // allows us to pass back the entire request to the callback
            },
            (req, username, password, done) => {
                User.findOne({where: { username: username }})
                .then((user)=>{
                    console.log("User found")
                })
                .catch(()=>{
                    console.log(err)
                })
            }
        )
    );


};