with temp as (
SELECT id from ams_cs_request_history
where "STATUS_ID" in (17,18,20,21,22,23)
and "DATE" > '2022-08-01'::date
and "DATE" < '2022-09-01'::date
) select
"STATUS_ID",
count(*) as CNT,
to_char("DATE",'YYYY-MM-DD') as DatePartChar
from temp
where "STATUS_ID" in (17,18,20,21,22,23) and id in (select id from temp)
group by "STATUS_ID", DatePartChar
limit 100;
select *, (select count(*) from product_country where product_country.product_id = products.id and product_country.country_id in (1,2)) from products;
select * from products where (select count(*) from product_country where product_country.product_id = products.id and product_country.country_id in (1,2)) = 2;
select count(*), product_id, group_concat(country_id) from product_country where product_country.product_id in (1,3) group by product_id;
строчку
echo $curl;
меняем на
echo $out;