我最近使用Yii开始了一个项目,我正在尝试习惯查询构建器.现在,我想使用连接进行查询并访问查询中的连接表数据,但我无法使以下工作:
我的(简化的)db-tables:
customer(#id,name)
employee(#id,name)
customer_employee(#customerid,#employeeid)
accounting(#id,customerid,started_date,finished_date,month,year)
我想执行以下查询,该查询将选择与某个员工关联的所有客户并显示其会计状态(started_date&finished_date)(如果适用)(否则为null).
以下查询工作正常,只是我无法使用cdbcriteria和Yii查询构建器:(同样,硬编码的id仅适用于此示例)
SELECT name, started_date, finished_date
FROM customer
RIGHT JOIN customer_employee ON customer.id=customer_employee.customerid
LEFT JOIN accounting ON customer.id=accounting.customerid
WHERE customer_employee.employeeid=2';
Run Code Online (Sandbox Code Playgroud)
请帮忙!
yii ×1