-2

我有三个表如下

  • 成就 id、emp_id、区域、dat

  • call_per_day id、emp_id、noofcalls、hotcalls、hotleads、dat

  • sales_statistics_master id、emp_id、目标、承诺、mnth、yrs

现在我想从上面三个表中提取员工的数据,包括他的成就、noofcalls、hotcalls、hotleads perday 与每月目标和承诺。

我正在使用以下查询。

SELECT  a.area, s.target,s.commitment,c.noofcalls,c.hotcalls,c.hotleads 
FROM   achievement as a, sales_statistics_master as s, calls_per_day as c 
WHERE  a.dat=CURDATE() AND 
       c.dat=CURDATE() AND 
       s.yrs= year(now()) AND 
       a.emp_id=s.emp_id AND
       a.emp_id=c.emp_id
4

1 回答 1

0

使用连接 using(field)。

select a.area, s.target,s.commitment,c.noofcalls,c.hotcalls,c.hotleads from
achievement as a join
sales_statistics_master as s using(emp_id) join
calls_per_day as c using(emp_id)
where a.dat=CURDATE() AND c.dat=CURDATE() AND s.yrs= year(now()) 
于 2013-05-21T17:42:58.200 回答