--测试数据
create table tb3(DATE varchar(10),fl varchar(10),num numeric)
insert tb3 select '12-01','牛',2
union all select '12-01','羊',1
union all select '12-02','猪',1
go
--查询
select date as '日期',
max(case fl when '牛' then num else 0 end) 牛,
max(case fl when '羊' then num else 0 end) 羊,
max(case fl when '猪' then num else 0 end) 猪
from tb3
group by date
go