两个表中都有多个具有相同emp id的记录 我需要查询
但我的下面的查询将首先获得最大记录,然后查询begindate date,end date和percent
我想按照上面指定的顺序查询。
SELECT app.amt, fac.email, fac.employee_id, fac.empid,
fac.first_name, fac.last_name, fac.department_id, fac.titlecode,
app.begindate, app.enddate, app.percent,
app.title_name, app.department_name
FROM appointment app
LEFT JOIN appointment app2 -- self-join to locate max
ON app.employee_id = app2.employee_id AND app.amt < app2.amt -- of app.amt
INNER JOIN faculty fac ON app.employee_id=fac.empid -- join to fac
WHERE app2.amt IS NULL -- isolate rows with max(app.amt)
AND app.begindate <= NOW()
AND app.enddate >= NOW()
AND app.percent>.50 group by empid