select b.descript,sum(a.quan) as quan,case WHEN c.descript is null THEN '团队预留' ELSE c.descript end as mkt_des ,count(distinct roomno) as room
from rsvsrc a
LEFT JOIN typim b on (a.hotelid=b.hotelid and a.type=b.code)
LEFT JOIN basecode c on (a.market=c.code and c.cat='mktcode') where a.accnt in (select accnt from master where sta='R' or sta='I') group by a.type,a.market;