selectcount(*) as aggregate from ((select `products`.*from `products` where `products`.`state` =1and `products`.`id` !=1147andnotexists (select*from `categories` innerjoin `category_product` on `categories`.`id` = `category_product`.`category_id` where `products`.`id` = `category_product`.`product_id` and `id` ='171') and `products`.`is_sp_check` !=1andexists (select*from `sale_attributes` where `products`.`id` = `sale_attributes`.`product_id` and `inventory` >0)) union (select `products`.*from `products` where `products`.`state` =1and `products`.`id` !=1147andnotexists (select*from `categories` innerjoin `category_product` on `categories`.`id` = `category_product`.`category_id` where `products`.`id` = `category_product`.`product_id` and `id` ='171') and `products`.`is_sp_check` =1andexists (select*from `sale_attributes` where `products`.`id` = `sale_attributes`.`product_id` and `sp_inventory` >0) orderby `created_at` desc) orderby `created_at` desc) as `temp_table`
selectcount(*) as aggregate from ((select `products`.*from `products` where `products`.`state` =1and `products`.`id` !=1147andnotexists (select*from `categories` innerjoin `category_product` on `categories`.`id` = `category_product`.`category_id` where `products`.`id` = `category_product`.`product_id` and `id` ='171') and `products`.`is_sp_check` !=1andnotexists (select*from `sale_attributes` where `products`.`id` = `sale_attributes`.`product_id` and `inventory` >0)) union (select `products`.*from `products` where `products`.`state` =1and `products`.`id` !=1147andnotexists (select*from `categories` innerjoin `category_product` on `categories`.`id` = `category_product`.`category_id` where `products`.`id` = `category_product`.`product_id` and `id` ='171') and `products`.`is_sp_check` =1andnotexists (select*from `sale_attributes` where `products`.`id` = `sale_attributes`.`product_id` and `sp_inventory` >0) orderby `created_at` desc) orderby `created_at` desc) as `temp_table`