select convert(varchar(13),ad_date),sum(f),sum(g),sum(p) from (
select ad_date,case t6_id when 36880 then ad_data end as f,
case t6_id when 36881 then ad_data end as g,
case t6_id when 36882 then ad_data end as p
from t_amdata where am_id=12 and t6_id in(36880,36881,36882)) as z
group by convert(varchar(13),ad_date)
order by convert(varchar(13),ad_date)