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;
select * from products;
select * from products where exists(select 1 product_country from product_country, country where product_country.product_id = products.id and product_country.country_id = country.id);
select * from products where exists(select 1 product_country from product_country where product_country.product_id = products.id and product_country.country_id = 3);
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;
public function user()
{
$instance = $this->newRelatedInstance(User::class);
$foreignKey = 'requests.id';
$localKey = 'request_id';
return $this->newHasOne($instance->newQuery(), $this, $foreignKey, $localKey)->join('orders.requests', 'requests.user_id', '=', 'users.id');
}