select count(distinct t_count.id) as count
from (
select
t_products.id as id
from
final_products as t_final_products
inner join
users as t_users
on
t_final_products."author" = t_users."id"
inner join
products as t_products
on
t_products."final_product" = t_final_products."id"
and
t_products."default" = 1 and
t_products."status" = 3 and
t_products."is_trade" = 1 inner join
product_category_relations as t_catrel
on
t_products."id" = t_catrel."product"
and
t_catrel."category" = :category
where
1=1
) as t_count