如何做一个像这样一个实际有效的 sql 语句:
select distinct store_id as myid,
(select count(*) from products where store_id = myid and delete_flag = true)
from products
where delete_flag = true
我想要一个包含每个商店 ID 的列以及具有该商店 ID 的已删除产品的数量。
如何做一个像这样一个实际有效的 sql 语句:
select distinct store_id as myid,
(select count(*) from products where store_id = myid and delete_flag = true)
from products
where delete_flag = true
我想要一个包含每个商店 ID 的列以及具有该商店 ID 的已删除产品的数量。
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
希望能帮助到你!
select store_id as myid , count(*) as noofdeleteditems from products where delete_flag = true group by store_id;