求判斷是否有調動職位的sql語句
一表teammem存有员工工号(staff),组别(team),开始日期(effdt),结束日期(expdt),要用sql抓出当月有调职位的员工号,开始日期,结束日期,sql该如何写?自己寫的語句只能抓有部門變動,但不能准確取到具體一個月有哪些人有職位調動。先谢各位了!select a.code, a.lname, b.effdt, b.expdt, c.lname as group0
from staff a, teammem b, team c
where a.code = b.staff
and b.team = c.code
and a.code like 'A%'
and b.staff in (select ds.staff from (select a.staff, count(a.staff)
from teammem a, staff b
where a.staff = b.code
and b.code like 'A%'
group by a.staff
having count(a.staff) > 1
) ds
)
order by a.code, b.effdt