SQLSTATE [42S22]:找不到列:在Laravel中使用hading子句吗?

时间:2019-02-17 16:40:26

标签: php laravel laravel-query-builder

我正在研究laravel项目,但首先是在核心php中创建的。我被困在一个可以在sql查询中正常工作的查询中,但是当我转换为laravel时,显示错误... sql查询如下:-

SELECT *,MAX(UNIX_TIMESTAMP( if(last_recur_date IS NULL, 
subscription_date,last_recur_date) )) as max, SUM( IF (active = 'y', 1, 0) ) AS 
acount, m.id AS member_id FROM members m INNER JOIN user_access_old ua ON m.id 
= ua.member_id GROUP BY m.id having acount=0 ORDER BY max DESC, m.id DESC, 
username ASC, ua.note DESC

但是当我尝试使用以下laravel查询其显示错误时:-

$members = Member::query();
$members = $members->join('user_access','user_access.member_id', '=', 'members.id')->select('members.id','members.first_name',
                          'members.surname','members.fullname','members.member_date','members.username','members.password',
                          'members.email','user_access.active','user_access.special_access','user_access.note',
                          DB::raw('SUM( IF (active = "y", 1, 0) ) AS acount'))
                    ->groupby('members.id')
                    ->having('acount',0)
                    ->orderby('max','desc')
                    ->orderby('members.id','desc')
                    ->orderby('members.username','ASC')
                    ->orderby('user_access.note','DESC')
                    ->paginate(60);  // when i replaced to get its working fine but i want to paginate the data

其显示如下错误:- SQLSTATE [42S22]:找不到列:1054“具有子句”中的未知列“ acount”(SQL:从members上的user_access内部联接user_access中选择count(*)作为聚合。 member_id = membersidmembers分组。id的{​​{1}} = 0)

0 个答案:

没有答案