我需要一些帮助。我想计算这些列的激活、停用和系统中的用户总数。当前输出包括 NAME 列中的名称两次输出,如下所示,其中包括 NULLS。我想消除 NULL 并获得每列的小计。希望我能得到一些帮助。
Current output:
- NAME Activated Deactivated
- MAX 25 NULL
- MAX NULL 5
- TAX 40 NULL
- TAX NULL 10
Desired output:
- NAME Activated Deactivated
- MAX 25 5
- TAX 40 10
-Total 65 15
谢谢。
select
case
when (upper(m.email) like '%max.com') then 'MAX'
when (upper(m.email) like '%tax.com') then 'TAX'
else 'OTHER'
end Name, count(*) 'Activated', null 'Deactivated'
from
membership.user_details d
inner join membership.aspnet_membership m
on m.userid = d.userid
inner join membership.user_notes n
on n.userid = d.userid
and n.created_on = (
select
min(created_on)
from
membership.user_notes
where
userid = n.userid
and note = 'received.'
)
and substring(convert(varchar(8),n.created_on,112),1,6) = '201209'
where
approved = 1
group by
case
when (upper(m.email) like '%max.com') then 'MAX'
when (upper(m.email) like '%tax.com') then 'TAX'
else 'OTHER'
end
union
select
case
when (upper(m.email) like '%max.com') then 'MAX'
when (upper(m.email) like '%tax.com') then 'TAX'
else 'OTHER'
end Name,
null 'Activated',
count(*) 'Deactivated'
from
membership.user_details d
inner join membership.aspnet_membership m
on m.userid = d.userid
inner join membership.user_notes n
on n.userid = d.userid
and n.CREATED_ON = (
select
min(created_on)
from
membership.user_notes
where
userid = n.userid
and note = 'SAAR received.'
)
and substring(convert(varchar(8),m.LastLockoutDate,112),1,6) = '201209'
where
approved = 1
group by
case
when (upper(m.email) like '%max.com') then 'MAX'
when (upper(m.email) like '%tax.com') then 'TAX'
else 'OTHER'
end