declare @sql varchar(8000)
set @sql = ''
select @sql = @sql + ',sum(case CONVERT(char(5),出货日期,101) when '''+出货日期+''' then 数量 else 0 end) ['+出货日期+']'
from (select distinct CONVERT(char(5),出货日期,101) 出货日期 from 有一表) tem
exec('select 斩刀号,底模'+@sql+',sum(数量) 总数量 from 有一表 group by 斩刀号,底模')
go
declare @sql varchar(8000)
set @sql = ''
select @sql = @sql + ',sum(case CONVERT(varchar(10),出货日期,111) when '''+出货日期+''' then 数量 else 0 end) ['+出货日期+']'
from (select distinct CONVERT(varchar(10),出货日期,111) 出货日期 from 有一表) tem
exec('select 斩刀号,底模'+@sql+',sum(数量) 总数量 from 有一表 group by 斩刀号,底模')
go
select 斩刀号 底模
(select 数量 form yourtable where 出货日期 = yourdatetime1)
(select 数量 form yourtable where 出货日期 = yourdatetime2)
(select sum(数量) form yourtable group by 斩刀号 底模) from yourtable;
select t.斩刀号 t.底模 a.10/10数量 b.10/25 (a.10/10数量+b.10/25 ) 总数量
from table t,
(select 斩刀号 底模 数量 from table where 出货日期=2003-10-10 ) a,
(select 斩刀号 底模 数量 from table where 出货日期=2003-10-25 ) b
where t.斩刀号=a.斩刀号 and t.斩刀号=b.斩刀号
and t.底模=a.底模 and t.底模 =b.底模