SQLSTATE[42S22]: Column not found: in laravel affte using having clause?

一个人想着一个人 提交于 2019-12-11 17:12:31

问题


I am working on laravel project but firstly it was created in core php. I am stuck in one query that is working fine in sql query but when i convert in to laravel its showing error... Sql query is below:-

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

But when i try using below laravel query its showing error:-

$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

Its showing below eroor :- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'acount' in 'having clause' (SQL: select count(*) as aggregate from members inner join user_access on user_access.member_id = members.id group by members.id having having acount = 0)

来源:https://stackoverflow.com/questions/54735320/sqlstate42s22-column-not-found-in-laravel-affte-using-having-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!