首页 > 解决方案 > 在 Magento 中添加一个以 SQL 查询为表的连接

问题描述

我有这样的查询=>

select table1.id, table1.name,
sorted_table2.marks from table1 LEFT JOIN (select DISTINCT student_id, marks from table2  order by marks DESC ) sorted_table2 ON table1.id = sorted_table2.student_id;

如何将其转换为 magento?

  $select->joinLeft( array('sorted_table2' => '(select DISTINCT student_id, marks from table2 orderby marks DESC AS sorted_table2)'),'table1.id = sorted_table2.student_id', '*');

这不起作用,因为它在查询中添加了“`”并将其视为表名。有没有办法可以做到这一点?谢谢!

标签: phpmysqlmagento

解决方案


推荐阅读