这是mysql中的查询
选择e_id,h_name, d_name,drf_name,credit_num,is_required,e_semester,stdate,endate,c_month,NUM 来自(SELECT electcourse.id e_id, h_id,d_id,ref_id,e_semester,stdate,endate,c_month,count(e_id)as num 来自
electcourse
=period
的{{1}}离开加入p_id
。id
左连接hospitalxdepartment
上的hd_id
= hospitalxdepartment。id
离开加入 关于选举的board
id
=e_id
其中st_id
=' admin'通过...分组e_id
)我在hospital
= hospital。h_id
左连接上离开加入id
department
=部门d_id
id
离开加入departmentreference
=ref_id
上的drfid
df_semester
= 105
这是我在laravel中的查询,但它收到了一些错误消息。
public function get_course($st_id,$semester){
$from=DB::table('electcourse')
->selectRaw('electcourse.id as e_id','h_id','d_id','ref_id','e_semester','stdate','endate','c_month','count(e_id) as num',)
->leftjoin('period','p_id','period.id')
->leftjoin('hospitalxdepartment','hd_id','hospitalxdepartment.id')
->leftjoin('board','electcourse.id','e_id')
->where('st_id','=',$st_id)
->where('e_semester','=',$semester)
->groupBy('e_id');
$query=DB::query()
->select('e_id','h_name','d_name','drf_name','credit_num','is_required','e_semester','stdate','endate','c_month')
->fromSub($from, 'T')
->leftjoin('hospital','h_id','hospital.id')
->leftjoin('department','d_id','department.id')
->leftjoin('departmentreference','ref_id','drfid')
->where('df_semester','=',$semester)->orderBy('c_month')->get();
return $query;
}
如果我没有在" select"中使用count,我确保它会起作用。串。 有谁知道如何使用正确的计数方法修复它?
错误消息:" Class App \ Repositories \ BoardRepository没有 存在" 这意味着DB格式错误。
答案 0 :(得分:0)
我找到了一种生成正确查询的方法,但它会收到错误消息。
查询功能
public function get_course($st_id,$semester){
$from=DB::table('electcourse')
->select('electcourse.id as e_id','h_id','d_id','ref_id','e_semester','stdate','endate','c_month',DB::raw('count(e_id) as num'))
->leftjoin('period','p_id','period.id')
->leftjoin('hospitalxdepartment','hd_id','hospitalxdepartment.id')
->leftjoin('board','electcourse.id','e_id')
->where('st_id','=',$st_id)
->where('e_semester','=',$semester)
->groupBy('e_id');
$query=DB::query()
->select('e_id','h_name','d_name','drf_name','credit_num','is_required','e_semester','stdate','endate','c_month')
->fromSub($from, 'T')
->leftjoin('hospital','h_id','hospital.id')
->leftjoin('department','d_id','department.id')
->leftjoin('departmentreference','ref_id','drfid')
->where('df_semester','=',$semester)->orderBy('c_month')->get();
return $query;
}
错误讯息:
" SQLSTATE [42000]:语法错误或访问冲突:1055 ' yangming567.electcourse.id'不在GROUP BY中(SQL:选择
e_id
,h_name
,d_name
,drf_name
,credit_num
,is_required
, 来自e_semester
,stdate
,endate
,c_month
electcourse
。id
为e_id
,h_id
,d_id
,ref_id
,e_semester
,stdate
,endate
,c_month
,计数(e_id)为来自electcourse
的数字 在period
=p_id
上离开加入period
。id
左连接hospitalxdepartment
=hd_id
上的hospitalxdepartment
。id
离开 在board
上加入electcourse
。id
=e_id
其中st_id
= admin和e_semester
= 105e_id
组{}T
左加入hospital
h_id
=hospital
。id
在department
=左加入d_id
=department
。id
在departmentreference
=上离开加入ref_id
drfid
其中df_semester
= 105订单c_month
asc) 但是,我将此错误消息查询复制到Mysql,这是工作!!!! 有人知道如何在laravel中修复我的查询吗?