我的 SQL 的最后部分似乎有问题。在我的 SQL NULL 中使用汇总功能实现 group by 时出现。如何修改 NULL 以便在此聚合 SQL 中将其替换为 TOTAL?
Current table returned
Name Activate Deactivate
Max 5 2
TAX 12 5
NULL 17 8
select
case
when (upper(m.email) like '%max.com') then 'MAX'
when (upper(m.email) like '%tax.com') then 'TAX'
else 'OTHER'
end Name,
SUM(case when substring(convert(varchar(8),n.created_on,112),1,6) = '201209' then 1 else 0 end) 'Activated',
SUM(case when substring(convert(varchar(8),m.LastLockoutDate,112),1,6)='201209' then 1 else 0 end) '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.')
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
with RollUp