【发布时间】:2019-03-07 03:15:24
【问题描述】:
如何从原生 php 转换为查询构建器 laravel
$statsMoneyInPlay = array();
$sql_query = "SELECT UNIX_TIMESTAMP(Date(ts))*1000 As ts, sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count(*) As moneyInPlay FROM enginepoker_log.poker WHERE GROUP BY Date(ts) ORDER BY Date(ts) LIMIT 30 ";
我已经创建了查询生成器,但仍然出现错误。 这就是错误
(2/2) QueryException SQLSTATE[42000]: 语法错误或访问 违规:1064 您的 SQL 语法有错误;检查手册 对应于正确语法的 MariaDB 服务器版本 在 'SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts) 附近使用,sum(pot + p1pot + p2pot + p3pot + p4p' 在第 1 行(SQL:选择 SELECT UNIX_TIMESTAMP(日期(ts)100 as ts), sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count() As moneyInPlay 来自
enginepoker_log.pokergroup byDate(ts)orderDate(ts)asc)
这是查询生成器:
$statsMoneyInPlay = DB::table('enginepoker_log.poker')
->selectRaw("SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts)")
->selectRaw("sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count(*) As moneyInPlay")
->groupBy("Date(ts)")
->orderBy("Date(ts)")
->get()
->toArray();
这是在刀片页面中
@php
foreach ($statsMoneyInPlay as $key => $value) {
echo "[".$value[0].", ".$value[1]."],";
@endphp
【问题讨论】:
-
请添加到目前为止您尝试过的操作。它应该可以帮助我们帮助您。
-
好的,我已经添加了我的问题@JaimeRojas
标签: php mysql database laravel