查詢員工最後一個月的工資情況

select * from employee

empid  name

001 張三

002 李四

003 王五


select * from salary

empid  month salary

001   1    100

001   2    200

001   3    300

002   1    200

002   2    400

003   3    500


select t3.name , t1.empid,t1.month,t2.salary from (

select empid,max(month) month from salary  group by empid) t1

 left join salary t2 on t2.empid = t1.empid and t2.month = t1.month

 left join employee t3 on t3.empid = t2.empid


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章