我想知道是否有可能使用fluent查询构建器在一个查询中获取多个字段的总和。
我目前有两个表:事件和参与者。出席者属于事件,有两个字段: total_raised和total_hours。我想要做的是选择所有事件和筹集的总金额/在该事件上花费的总小时数。现在,如果我只使用SQL,我会做一些如下的事情:
SELECT Event.id, sum(Attendees.total_raised), sum(Attendees.total_hours)
FROM Events JOIN Attendees ON Events.id = Attendees.event_id
GROUP BY E
如何将此查询转换为laravel db查询。 SELECT * FROM {
Select * from organizers
Order by organizers.rank
} Group by t.department 这是query的简化版本。实际上,内部查询有更多的where子句,并使用laravel db查询构建。 编辑:我知道原始查询。但这不是我要找的。内部查询很复杂,并且有很多条件where子句。我想保留我在那里使用的db query对象。
我试图使用查询构建器在laravel中显示一些列的总和,但得到了这个错误:
htmlentities() expects parameter 1 to be string, object given
以下是查询:
$purchase = DB::table('purchases')
->join('currencies', 'currencies.cur_id', '=', 'purchases.currency_id')
->selectRaw('purchases.*, cu
我对laravel是个新手,对执行查询还不太熟悉。我被这个我搞不清楚的问题所困扰。
Models: Flag -> Quote -> QuoteItems
1 - Quotes has many QuoteItems | QuoteItems has One Quote
2 - Each Quote has one Flag(e.g accepted, rejected)
1- QuoteItems contains Profit and Price fields.
我需要的总和(利润)和总和(价格)从所有这些报价,是与一个旗帜相关。
我有一个运行在mysql 5.7.11上的数据库,并将大量数据放入一个包含JSON列的表中。我得到了一个类似这样的原始查询。
select * from `note`
where `note_structure_id` = 3
and JSON_EXTRACT(LCASE(data), '$._letter') = 'a'
and JSON_EXTRACT(data, '$._number') = 1
在sequel pro或phpmyadmin中运行,它会给我一个我期望的结果;
{"_letter": "A"
我正在尝试在Laravel应用程序中配置一个查询,它等同于:
SELECT SUM(balance), name FROM db.statement_versions
INNER JOIN statements ON statement_versions.statement_id = statements.id
INNER JOIN accounts ON statements.account_id = accounts.id
GROUP BY name;
当我在中运行这个查询时,它可以工作,但是当我尝试用MySQL查询构建器将它转换成PHP时,我得到了一个错误。我最终想要的是返回所有的acc
Lumen具有带有select方法的DB外观
$results = DB::select('select * from users where id = :id', ['id' => 1]);
但这在WHERE in case中不起作用。
DB::connection('db')->selectOne("many lines of sql WHERE my_id IN (:my_id) ", ["my_id" => $new_ids]);
当然,也可以使用查询构建器,
DB::connection
我想知道是否可以使用fluent查询生成器在一个查询中获取多个字段的总和。
例如:
SELECT sum(nb_visit + nb_recommendation)
FROM Stats
GROUP BY id
到目前为止,我拥有的是:
Stats::sum('nb_visit+nb_recommendation');
我正在使用mongoDb的laravel molequent,我想编写一个查询来比较两个日期之间的当前月份。假设我有start_date和end_date,如果我用mysql写查询,它将是:
select * from table where month(curdate()) between month(start_date) and month(end_date) ;
现在,我必须使用laravel查询构建器用mongoDb编写这个查询。
我有一个查询,其中包含多个子查询,这些子查询带有我试图在Laravel模型中构建的参数。
我是Laravel 4的新手,所以我真的需要一些帮助,知道什么是“最好的”方法。
我需要重现的查询是:
Select userId from facultyAvailability
where
:startDate between startDate and endDate
and :endDate between startDate and endDate
and userId NOT IN(
Select
userId
from
schedul
这是一个简化的用例,只是为了说明我想要实现的目标:
考虑一下纯SQL中的查询:
SELECT url, 1 AS active
FROM `modules`
WHERE 1
如何使用查询构建器添加常量活动列?
以下是我的查询构建器,没有额外的列:
DB::table('modules')
->get(['url']);
我正在构建一个SQL查询(Postgres很重要),它将返回包含所有字段和引用总数的文章列表。
$a = Articles::select(DB::raw('
*,
count(
select * from "references"
where exists (select * from "users" where "users"."reference_id" = "references".
我有这样的疑问: public static function totalByAgent(int $agentId)
{
return PropertyListing::select(
DB::raw('SUM(property_listing.rental) as rental'),
DB::raw('SUM(property_listing.sale) as sale'),
'property_category.name as category_name',
'
我有两个表,这两个表都有完全相同的字段名称和数据类型。
问题: 1)我无法从两个列接收数据2)我还需要计算两个表中的电话号码
字段名称为member_id、name、phone
`SAMPLE DATA IN MEMBER TABLE`
------------------------------
member_id | name | phone |
------------------------------
100000 | ABC | 9876543210 |
-----------------------------*
`NOW SAMPLE DATA IN MEMBE
我正在使用Laravel创建一个简单的REST服务,它将点几何插入到PostgreSQL (extended )表中,以及另外两个字符串值。由于雄辩(据我所知)不支持PostGIS函数,所以我使用的是原始SQL查询。
我的控制器看起来是这样的:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Trgovina;
use Validator;