0

如何使用 where class in 从多个表中获取数据NotORM

代码

SELECT tbl1.description,
concat(tbl2.first_name, ' ', + tbl2.last_name) name,
count(tbl3.description)
FROM table1 tbl1, table3 tbl3,table2 tbl2
WHERE tbl1.id = tbl3.s_id
and tbl1.value= tbl2.value
group by tbl1.description,name
4

2 回答 2

0

NotORM 旨在处理命名良好的表和列。默认命名约定会导致这种请求(如果我猜你需要的话):

SELECT table1.description,
    CONCAT(table2.first_name, ' ', + table2.last_name) name,
    COUNT(table3.description)
FROM table1, table2, table3
WHERE table1.id = table3.table1_id
  AND table2.id = table1.table2_id
GROUP BY table1.description, name

在 notOrm

$db->table1()
  ->select("table3.description")
  ->select("CONCAT(table2.first_name, ' ', + table2.last_name) AS name")
  ->select("COUNT(table3.description) AS c")
  ->group("table1.description, name");

无需将这些表连接在一起。这是 NotOrm 的工作。

于 2014-08-21T13:30:00.993 回答
0

我想,你可以试试这样

$db->table1()->select("description,(SELECT first_name FROM table2 where table2.value=table1.value)as firstname")->group("description")->fetch();
于 2014-08-16T07:17:52.987 回答