My Laravel 5 app includes a dynamic query builder for report running. I need some group by clauses in there and have run into a problem. If I use actual sql in there I can have issues as sometimes there needs to be a sql command in amongst the sql (as opposed to straightforward column names), ie - DAYNAME(table_name.date_column)
. Laravel mangles this:
\`DAYNAME(table_name\`.\`date_column)\`
For the select part of my query I can use selectRaw, but there does not seem to be an equivaent for group by.
我曾想过使用别名(所有的 Select 都是别名),但Laravel也将它们包装成"`"字符.此外,我的应用程序需要同时使用MySQL和SQL Server,据我所知,后者不允许在查询的分组中使用别名.
我可以在illumb\Database\Query\Grammars\Grammar中找到编译group by的方法(compileGroups),我想我可以重写它,但我不太确定该怎么做(已经阅读了Laravel文档).