I’m using laravel 5.3 and php 7.4.33.
This is the code:
$extensionCustomerIds = DB::table('crm_extension_customers as a')
->join('crm_extension_customer_merchandises as b', 'a.id', '=', 'b.extension_customer_id')
->where('a.created_at', '<', DB::raw('DATEADD(DAY, -3, GETDATE())'))
->groupBy('b.id')
->havingRaw('COUNT(*) = COUNT(CASE WHEN (b.item_amount_used IS NOT NULL AND b.item_amount_used = b.total_item_amount)
OR
(b.expiration_date IS NOT NULL AND b.expiration_date <= GETDATE()) THEN 1 END)')
->pluck('a.id');
dd($extensionCustomerIds);
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The multi-part identifier “b.item_amount_used” could not be bound. (SQL: select [t_a].[id] from [t_crm_extension_customers] as [t_a] inner join [t_crm_extension_customer_merchandises] as [t_b] on [t_a].[id] = [t_b].[extension_customer_id] where [t_a].[created_at] < DATEADD(DAY, -3, GETDATE()) having COUNT(*) = COUNT(CASE WHEN (b.item_amount_used IS NOT NULL AND b.item_amount_used = b.total_item_amount) THEN 1 END))
Does anyone know what I did wrong?