SQL 语句 根据最小值查询用户id

2024-12-04 00:41:19
推荐回答(2个)
回答1:

select userID from user a left outer join(select min(checkper) as checkper,role_id,dept_id from role group by dept_id,role_id) b on a.role_id=b.rold_id and a.dept_id=b.deptid

回答2:

SELECT tr.checkper,tu.user_id,tr.dept_id
  FROM Tuser tu
  RIGHT JOIN role tr ON tr.rloe_id=tu.role_id
WHERE checkper=(SELECT MIN(checkper) FROM role)