本帖最后由 lurenheheyy 于 2011-06-02 22:15:12 编辑

解决方案 »

  1.   

    insert into 喂食晴雨表
    select 三餐消费编号=convert(varchar(8),交易时间,112),convert(varchar(10),交易时间,120) 日期,sum(金额) 总额 
    from [一卡通2011-05]
    where 交易地点 not in('优乐购三分店','学生食堂小卖部') and 交易类型!='第一银行领款'
    group by convert(varchar(8),交易时间,112),convert(varchar(10),交易时间,120)select * from 喂食晴雨表
    /**
    三餐消费编号   日期         总额
    -------- ---------- ---------------------------------------
    20110522 2011-05-22 13.00
    20110527 2011-05-27 22.30
    20110528 2011-05-28 18.20
    20110529 2011-05-29 9.70
    20110530 2011-05-30 9.10
    20110531 2011-05-31 7.00(6 行受影响)
    **/
      

  2.   

    测试数据
    if object_id('[一卡通2011-05]') is not null drop table [一卡通2011-05]
    go
    create table [一卡通2011-05]([序号] int,[交易时间] datetime,[交易地点] varchar(14),[金额] numeric(5,2),[余额] numeric(5,2),[交易类型] varchar(12))
    insert [一卡通2011-05]
    select 1,'2011-05-31','学生食堂二厅9',2.00,87.90,'餐费支出' union all
    select 2,'2011-05-31','学生食堂二厅13',0.40,89.90,'餐费支出' union all
    select 3,'2011-05-31','美食城2-1',2.50,90.30,'餐费支出' union all
    select 4,'2011-05-31','学生食堂一厅20',0.60,87.30,'餐费支出' union all
    select 5,'2011-05-31','学生食堂一厅1',1.50,85.80,'餐费支出' union all
    select 6,'2011-05-30','学生食堂二厅1',0.60,101.30,'餐费支出' union all
    select 7,'2011-05-30','学生食堂二厅9',2.50,98.80,'餐费支出' union all
    select 8,'2011-05-30','美食城9-2',6.00,92.80,'餐费支出' union all
    select 9,'2011-05-29','美食城9-2',6.50,101.90,'餐费支出' union all
    select 10,'2011-05-29','学生食堂一厅3',2.00,108.40,'餐费支出' union all
    select 11,'2011-05-29','美食城8-1',1.20,110.40,'餐费支出' union all
    select 12,'2011-05-28','美食城9-2',6.50,120.10,'餐费支出' union all
    select 13,'2011-05-28','美食城11-1',4.00,111.60,'餐费支出' union all
    select 14,'2011-05-28','美食城11-2',4.50,115.60,'餐费支出' union all
    select 15,'2011-05-28','美食城8-1',1.20,126.60,'餐费支出' union all
    select 16,'2011-05-28','学生食堂一厅20',2.00,127.80,'餐费支出' union all
    select 17,'2011-05-27','美食城9-2',7.00,145.90,'餐费支出' union all
    select 18,'2011-05-27','学生食堂小卖部',4.00,141.90,'餐费支出' union all
    select 19,'2011-05-27','学生食堂一厅3',2.00,152.90,'餐费支出' union all
    select 20,'2011-05-27','美食城8-1',1.20,154.90,'餐费支出' union all
    select 21,'2011-05-27','学生食堂二厅6',2.50,129.80,'餐费支出' union all
    select 22,'2011-05-27','学生食堂二厅13',0.60,132.30,'餐费支出' union all
    select 23,'2011-05-27','优乐购三分店2',9.00,132.90,'洗衣支出' union all
    select 42,'2011-05-22','学生食堂一厅4',200.00,217.00,'第一银行领款' union all
    select 43,'2011-05-22','美食城11-1',4.00,213.00,'餐费支出' union all
    select 44,'2011-05-22','美食城9-2',7.50,17.00,'餐费支出' union all
    select 45,'2011-05-22','美食城8-1',1.50,24.50,'餐费支出'