【问题标题】:How to fetch data from multiple tables using where class in NotORM?如何使用 NotORM 中的 where 类从多个表中获取数据?
【发布时间】:2014-07-30 04:54:15
【问题描述】:

如何使用NotORM中的where类从多个表中获取数据?

代码

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

【问题讨论】:

    标签: notorm


    【解决方案1】:

    我想,你可以这样尝试

    $db->table1()->select("description,(SELECT first_name FROM table2 where table2.value=table1.value)as firstname")->group("description")->fetch();
    

    【讨论】:

      【解决方案2】:

      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 的工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多