假设我有一张这样的桌子
ID, SN, USED
002, 183000153206, 0
002, 180000205206, 0
002, 188000373206, 0
002, 186000495206, 0
002, 181000521206, 0
001, 180000107106, 0
001, 181000206106, 0
001, 182000337106, 0
001, 180000453106, 1
001, 188000557106, 0
001, 184000639106, 0
我想计算每个ID使用的sn计数,如果我的SQL脚本是正确的,结果可能是:
ID, USED_Count
002, 0
001, 1
这是我到目前为止所做的,但它只显示了ID 001记录,没有ID 002。
select id, count(sn) as sums
from sn_table
where sn is not null
and used is not null
group by id
--having sums >= 0
我知道情况
使用不为空
似乎不太对,但我只是在这里储存了几个小时,我怎么能做到呢?