create table1
(
id  int not null identity(1,1)
时间,datetime
金额,money)
insert into table1(时间,金额) values('2009-1-1 12:20','10')
insert into table1(时间,金额) values('2009-1-2 13:20','20')
insert into table1(时间,金额) values('2009-1-1 12:20','10')
insert into table1(时间,金额) values('2009-1-2 14:20','20')
insert into table1(时间,金额) values('2009-1-1 16:20','10')求一条sql select语句后得出下面的查询结果
时间           金额
2009-1-1        30
2009-1-2        40  

解决方案 »

  1.   

    select 时间,sum(金额) as 金额 from table1 Group by 时间
      

  2.   

    select 时间,sum(金额) as 金额 from table1 Group by 时间
      

  3.   

    select 时间,sum(金额) as 金额 from table1 Group by 时间
    楼上的很好用啊
      

  4.   

    来晚了友情UP一下
    LZ最好去看看PL/SQL的基本语法,里面都有介绍的
      

  5.   

    select convert(char(10),时间,126) as 日期 ,sum(金额) as 金额 from 表 
    group by convert(char(10),时间,126)
      

  6.   


    select CONVERT(varchar(100), 时间, 23) 时间,sum(金额) 金额 from table1
    group by  CONVERT(varchar(100), 时间, 23)
      

  7.   

    如果你的时间是 2009-1-1 格式则:select subString(cast( 时间 as varchar(20)),1,8),SUM(金额) 金额
    from table
    group by subString(cast( 时间 as varchar(20)),1,8)
    如果是2009-01-01 格式 则:select subString(cast( 时间 as varchar(20)),1,10),SUM(金额) 金额
    from table
    group by subString(cast( 时间 as varchar(20)),1,10)
      

  8.   

    select convert(char(10),时间,126) as 日期 ,sum(convert(int,金额)) as 金额 from table1 
    group by convert(char(10),时间,126)
      

  9.   

       
    create table1 

    id  int not null identity(1,1) 
    时间,datetime 
    金额,money ) 
    insert into table1(时间,金额) values('2009-1-1 12:20','10') 
    insert into table1(时间,金额) values('2009-1-2 13:20','20') 
    insert into table1(时间,金额) values('2009-1-1 12:20','10') 
    insert into table1(时间,金额) values('2009-1-2 14:20','20') 
    insert into table1(时间,金额) values('2009-1-1 16:20','10') 求一条sql select语句后得出下面的查询结果 
    时间          金额 
    2009-1-1        30 
    2009-1-2        40   
      

  10.   

    SELECT CONVERT(VARCHAR(10),时间),SUM(金额)金额 FROM TB GROUP BY CONVERT(VARCHAR(10),时间)