如何使用一个SQL查询返回来自两个或多个不同作者的帖子?Authors数组是从数据库接收的,对于每个用户来说都是不同的(这取决于您所跟踪的作者)。
我用作者的ID返回$array变量。
$array = array(15, 12, 18); //this array is returned from database and is always different
$posts = DB::table('posts') -> where('author', $array]) -> orderBy('date', 'DESC
我是Laravel的新手,我有一个复杂的查询要构建。除了当用户请求多个标记(tags = 1, 2, 3)时,我设法对其进行排序。显示的产品必须有用户要求的所有tags (不仅仅是一两个,而是所有的)。
我在SQL中有一个查询(这个例子是两个标记,我会根据传递的标记数量将其转换为不同的数字):
SELECT m.*
FROM meals m
WHERE EXISTS (
SELECT 1
FROM meals_tags t
WHERE m.id = t.meals_id AND
t.tags_id IN (227,25)
HAVING COU
SELECT Code_tank, temperature, salinity, PH, parameters.created_at as created_at FROM parameters WHERE id IN (SELECT MAX(id) FROM parameters group by code_Tank) ORDER BY code_tank ASC;
我一直试图将这个SQL语句放在laravel中,但没有,这是我尝试的代码:
$testMonitor= DB::table('parameters')
->select('code_Tank&
如何在laravel中执行此sql查询?
SELECT * FROM `examination` WHERE `id` in (select `exam_id` from
`exam_supervision` where `lecturer_id` in (select `id` from `lecturers` where `id`=1));
拉威尔看起来很困惑。有没有人能给我一个确切的答案?
谢谢
我使用的是laravel 8,需要从表单选择的数据中选择数据,并在我的ServClinic表中仅插入Clinic_id和Service_id。这是我的模型需要从多对多关系中保存数据,并进一步获取数据我的临床模型 <?php
class Clinic extends Model
{
use HasFactory;
protected $table = "clinics";
public function services(){
return $this->belongsToMany(ServiceData::class,&
我有一个mysql查询,在这个查询中,我需要使用或检查2列中的值数组。简而言之,我有一个数组,需要在2列上使用或条件检查.。
使用sql
SELECT *
FROM table_name
WHERE col_1 IN (1, 8, 3)
OR
WHERE col_2 IN (1, 8, 3)
使用龙骨
$mu = DB::table('users')
->join('table_a', 'users.id', '=', 'table_a.user_id')
假设我有一张像这样的桌子
create table object_properties {
uuid id;
uuid source_id; // the object which has this property
string name; // the property name
uuid value_id; // the property value object
}
我想找到所有的object_properties
WHERE source_id IN [1, 2, 3, 4, 5] AND name IN ['foo', 'bar']
如何为Zend3编写sql?
我做不到。
select email as publihser_email, phone_number as publisher_phone_number, CONCAT(first_name,' ',last_name) as publisher_name
from users
where id in(
select distinct publisher_id from apartments where publisher_type=0
)
UNION
select email as publihser_email, phon
有人可以帮我用Eloquent转换这个SQL查询: SELECT DISTINCT date FROM `non_working_days` where YEAR(date)="2021" AND city IN ('Paris','NewYork'); 目前我有这样的想法: $city = ['Paris','NewYork'];
$data = Model::query()
->distinct()
->whereYear('date', $year)
->wh
我想使用GROUP BY和CONCAT获取数据。我可以在SQL内联编辑器中获得这些数据,我想知道如何在Laravel中获得这些数据。我想要我想要的结果,如附件中的图像
我的SQL查询是:
SELECT created_at, GROUP_CONCAT(answer) FROM answers
where cid=293 and qid in (7, 8, 9, 10, 11, 12)
group by created_at
我有一个sql查询,我想知道它是否可以用eloquent编写。 有两个表: Brands和Products。 我想知道某一类产品的品牌。 下面是它目前的样子 \DB::select('select * FROM brands WHERE id in ( select brand_id from products WHERE category_id IN (220, 222, 223) GROUP by brand_id )'); 以上是工作,我需要帮助将其转换为雄辩。
我正在开发一个API,它负责获取购物车(列)值等于1的(记录)数据,请帮助我解决这个问题。
,这是我如何获得错误的方法
Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'bookstore.books.id' which is not functionally depe
我想使用Linq向实体查询sql服务器数据库。我希望使用以下Sql查询对以下表进行筛选:
DECLARE p0...
SELECT * FROM Boards b
WHERE b.ownerid = p0 or
b.id IN (SELECT s.boardid FROM Shares s WHERE s.userid = p0)
CREATE TABLE [dbo].[Boards] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[OwnerId] NVARCHAR (128) NULL,
[ShortName]
我在laravel控制器的数据库中查询select max数据。但是,我想使用有说服力的版本来做到这一点。 这是我的sql查询 DB::select('SELECT saldo
FROM akun_trxes
WHERE akun_id IN (SELECT id FROM akuns WHERE akun_parrent = 1)
AND id IN (
SELECT MAX(id)
FROM akun_trxes
GROUP BY akun_id
我该如何使用eloquent在Laravel 4.2中编写这个SQL查询?
SELECT *
FROM participants
WHERE user_id IN (1, 2)
GROUP BY convo_id
HAVING count(DISTINCT user_id) = 2
AND count(DISTINCT convo_id) = 1
我已经试过了
Participant::whereIn('user_id', $participantIds)
->groupBy('convo_id')
我来自$stemp [hasil] => 20,8,24的数组
我的sql查询SELECT * FROM 'objek' WHERE objek.id IN ('20','8','24')
我正在尝试DB::select("SELECT * FROM 'objek' WHERE objek.id IN ('$stemp')");
这不是工作,并获得错误数组字符串转换。
我有这样的代码,我想要获得具有教师角色的列表用户,其中每个教师将有一个用于个人细节的对象,一个用于学校细节的对象。
public function index(){
$teachers = User::whereHas('roles' , function($q){$q->where('name','isTeacher');})->get();
foreach($teachers as $teacher){
$teacher_id = $teacher->id;
我有以下SQL查询:
SELECT * from db.tableA WHERE field in (SELECT id FROM db.tableB where other_field = value);
我希望select from field where tableA在由子查询返回的值数组中。问题是:我怎样才能用eloquent做到这一点?我目前的解决方案(我认为非常丑陋)如下:
$a = \App\tableB::where("other_field", "=", $value)->select('id')->get();
$
我有一个原始的SQL查询
SELECT cc.name, pp.population
FROM population_table pp
WHERE pp.country_name IN (
SELECT cc.name
FROM `countries` cc
)
GROUP BY pp.country_name
上面的查询给出了countries表中的国家和地区列表以及population值。
我试图通过将查询拆分为两部分来将此查询转换为eloquent。我在数据库级别使用了这个口才。
public function getCountriesWithPopulation()
我需要sql查询,但我需要使用Eloquent:
"SELECT * FROM Pass WHERE serial_number=$registered_serial_numbers AND (updated_at IS NULL OR updated_at >= $passesUpdatedSince)"
我尝试过,但有错误:
$registered_passes = Pass::where('serial_number', $registered_serial_numbers)->where("updated_at IS NULL OR
在我的Laravel申请中,我有以下模式:课程、活动、学生、入学、出勤率。
a hasMany Events。当学生注册某门课程时,生成注册,因此课程hasMany注册。是学生hasMany出勤记录。是一个事件,belongsTo是一个学生。
我想检索至少有一名学生的课程列表,这些学生的出勤率记录比课程中预计的活动总数还要少。例如,如果一个课程有10个活动,我需要得到所有的课程,至少有一个学生有少于10个预期出席这些活动的记录。
作为一个临时解决方案,我在我的课程模型中使用了一个嵌套的foreach循环:
public function getEventsWithExpectedAttenda
几天来,我一直在绞尽脑汁地想要写这个查询,但是什么也没能实现。我有这些表格: Agents (Users)
id
name
email
password
created_at
updated_at
Customers
id
agent_id
firstname
lastname
email
created_at
updated_at
Orders
id
customer_id
product_id
amount
Customer_Tags
id
customer_id
name
Products
id
我试图将一个join附加到我的查询生成器中,并得到以下错误:
消息:"SQLSTATE23000:完整性约束违反:在where子句中的1052列'id‘是模棱两可的(SQL: select * from accommodation_rooms is room_pricing_histories on accommodation_rooms.id = room_pricing_histories.accommodation_room_id和room_pricing_histories.from_date = 2019-10-05 15:49:21其中<code>d10
我需要从多个相关表中执行DQL delete。在SQL中是这样的:
DELETE r1,r2
FROM ComRealty_objects r1, com_realty_objects_phones r2
WHERE r1.id IN (10,20) AND r2.id_object IN (10,20)
我需要使用DQL执行此语句,但我被困在这一点上了。:(
<?php
$dql = Doctrine_Query::create()
->delete('phones, comrealtyobjects')
->from(&
我有两张桌子
risks
risk_id name area_id
1 a 1
2 b 1
risk_areas
id name parent_id
1 a 0
2 b 1
3 c 1
4 d 2
这是我的sql查询:
SELECT * FROM `risks` WHERE (`register_id` = 29 AND `area_id` = 1)
OR (`area_id