[英]How do I translate a partial expression of SQL functions to SQL::Abstract?
I have a query that I would like to run as a DBIC result instead of query string. 我有一个查询,希望以DBIC结果而不是查询字符串的形式运行。
The query is this: 查询是这样的:
"SELECT posts.*, (((LOG10(SUM(points.point) + 1) * 287015) +
UNIX_TIMESTAMP(posts.create_time))) as total FROM posts left join points ON
post.post_id = points.post_id GROUP BY posts.post_id ORDER BY total DESC"
Since I got relationships set up, I think i can avoid left join part on the query (my relationships in schema Post.pm file have has_many relationship set up to points table, so I am guessing that will do a left join with vibe points. 由于我已经建立了关系,因此我想可以避免在查询中使用左联接(我在架构Post.pm文件中的关系已将has_many关系设置为points表,因此我猜测这将对vibe点进行左联接。
What I have now is the following: 我现在所拥有的是:
$resultset->search(
{},
{
select => [({sum => points.point} + 1) * 287015],
as => [ 'total' ],
group_by [qw/ id /],
order_by => { -desc => 'total' },
}
);
I am having a problem integrating the LOG10 and sum points with addition of 1 and multiplication of 287015. 我在将LOG10和求和点与1加和287015相乘时遇到问题。
Any help is appreciated, I know that whatever I have there as a result, is not the way to do it, but I tried something and it didn't work. 感谢您提供的任何帮助,我知道所得到的任何东西都不是解决问题的方法,但是我尝试了一些尝试却没有成功。 Thanks!
谢谢!
Untested because you didn't provide a schema and example data: 未经测试,因为您未提供架构和示例数据:
'+select' => [{
\'(LOG10(SUM(points.point) + 1) * 287015) + UNIX_TIMESTAMP(me.create_time)'
-as => 'total'
}],
join => 'points',
group_by => 'me.post_id',
order_by => { -desc => 'total' },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.