سلام و روز خوش
1- ظاهرا یک مسئله pivoting ساده است:
select * from
(select id , nam , nam_fa , naumber, stat
from status
where stat in (0,1) and datee > '1400/01/02' and mz='mard'
) as input
pivot (count(id) for stat in ([0],[1])) as output
و برای اسم ستونها:
select nam , nam_fa , naumber,
isnull([0],0) as [ارسال نشده],
isnull([1],0) as [ارسال شده]
from
(select id , nam , nam_fa , naumber , stat
from status
where stat in (0,1) and datee > '1400/01/02' and mz='mard'
) as input
pivot (count(id) for stat in ([0],[1])) as output