私は2つのテーブルempmasterとallocation. union2 つのテーブルから結果を取得するために、SQL 操作を行っていました。他にもありempmasterます。テーブルには、 と呼ばれる別のフィールドからの外部キーが含まれています。次を満たすものを取得する必要があります。empidempdetailsallocationempidempmasterper_allocempdetails
empmaster.empidありませんallocation.empid。empmaster.empidでallocation.empid and allocation.per_alloc < 100。
私が使用したMySQLクエリは次のとおりです。
select distinct(tbl_empmaster.emp_fname)
from tbl_empmaster
where tbl_empmaster.emp_id not in(select tbl_allocation.emp_id
from tbl_allocation)
union
select distinct(tbl_empmaster.emp_fname)
from tbl_empmaster
where tbl_empmaster.emp_id in(select tbl_allocation.emp_id
from tbl_allocation
group by emp_id
having sum(per_alloc) < 100)
これは取得するだけempdetailsです。たとえば tbl_empmaster.emp_fname、取得する必要がありますsum(per_alloc) from select tbl_allocation!!! 試してみると、多くのエラーが発生しました。正しい方法を教えてください。