我现在的数据:
斩刀号  底模  出货日期     数量
C-750   S-28  2003-10-10   100
C-750   S-28  2003-10-25   200需要的结果:
斩刀号  底模  10/10数量  10/25  总数量
C-750   S-28  100        200    300请教各位大虾这个怎么实现!

解决方案 »

  1.   

    jhwh(弹剑长歌) :能不能说详细一点!谢谢!
      

  2.   

    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.底模 
      

  3.   

    TRANSFORM Sum([数量])
    SELECT [斩刀号], [底模], Sum([数量]) AS [总数量]
    FROM 表名
    GROUP BY [斩刀号], [底模]
    PIVOT Format([日],"Short Date");
      

  4.   

    select 斩刀号  底模 
           (select 数量 form yourtable where 出货日期 = yourdatetime1)
           (select 数量 form yourtable where 出货日期 = yourdatetime2)
           (select sum(数量) form yourtable group by 斩刀号  底模) from yourtable;
      

  5.   

    TO goldencity(响马) :因为一个月只能有两个出货期,所以那个10/10,10/25在程序中可能得到,只是表头显示而已!delphi_xizhousheng(西周生):这段SQL语句我怎么试都是会出现多条记录,我想得到的结果是只有一条,问题估计是在 a.10/10数量  b.10/25 这边!其实上面这些方法我在大富翁有看过类似的,不过SQL Server我不熟悉,很多函数不知道怎么用!所以我希望各位能给我一个比较完整的!视图:vOrderSort
    字段:cCutNo,cXuanTou,cDimo,fSQty
    里面只有两条记录:斩刀号   楦头  底模    出货日期       数量
    C-750    A01   S-28    2003-10-10     100
    C-750    A01   S-28    2003-10-25     200
      

  6.   

    SQLServer: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 有一表) temexec('select 斩刀号,底模'+@sql+',sum(数量) 总数量 from 有一表 group by 斩刀号,底模')
    go
    如果是oracle再和我说
      

  7.   

    如果你不要考虑年的话: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 有一表) temexec('select 斩刀号,底模'+@sql+',sum(数量) 总数量 from 有一表 group by 斩刀号,底模')
    go
      

  8.   

    感谢pengdali(大力 V3.0)!问题解决了!