Reputation: 1094
how to do an sql statement like this one that actually works:
select distinct store_id as myid,
(select count(*) from products where store_id = myid and delete_flag = true)
from products
where delete_flag = true
I want a column with every store id and the number of deleted products with this store id.
Upvotes: 0
Views: 72
Reputation: 8580
Hope it helps!
select store_id as myid , count(*) as noofdeleteditems from products where delete_flag = true group by store_id;
Upvotes: 0
Reputation: 204746
select store_id,
count(*) as all_product_count,
sum(case when delete_flag = 1 then 1 else 0 end) as deleted_product_count
from products
group by store_id
Upvotes: 3