Vanddel
Vanddel

Reputation: 1094

SQL statement not working

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

Answers (2)

immayankmodi
immayankmodi

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

juergen d
juergen d

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

Related Questions