助けが必要です。これらの列について、システム内のアクティブ化されたユーザー、非アクティブ化されたユーザー、および合計ユーザーの数を取得したいと考えています。現在の出力には、以下に示すように NAME 列内の名前が 2 回含まれており、NULL が含まれています。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