导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

求一sql语句

vivianfdlpw 2005-02-25 09:14:20
有一张表h_order,有四个字段:

ID bianhao pv riqi
1 00001 10 2005-01-01 09:02:35
2 00001 20 2005-01-01 09:05:10
3 00002 15 2005-01-01 09:02:35
..................

在h_order中,同一个bianhao可以对应多条记录。
如何按照日期汇总同一个bianhao的pv到另一个表中?
比如上边的三条数据,按照介于2005-01-01 00:00:00到2005-01-02 00:00:00
之间的纪录汇总pv产生下面的结果:
bianhao pv
00001 30
00002 15

谢谢
...全文
62 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Qihua_wu 2005-02-25
insert into 汇总表(bianhao,pv)
select bianhao,sum(pv)
from h_order
where riqi >= cast('2005-01-01 00:00:00' as datetime) and riqi<= cast('2005-01-02 00:00:00' as datetime)
group by bianhao
回复
Softlee81307 2005-02-25
--------請試下面的語句----
insert into 另一个表(bianhao,pv)
select bianhao,pv=sum(pv) from h_order
where cast(convert(varchar(10),riqi,120) as datetime) between '2005-01-01' and '2005-01-02'
group by bianhao,convert(varchar(10),riqi,120)
回复
Softlee81307 2005-02-25
insert into 另一个表(bianhao,pv)
select bianhao,pv=sum(pv) from h_order
where cast(convert(varchar(10),riqi,120) as datetime) between '2005-01-01' and '2005-01-02'
group by bianhao,convert(varchar(10),riqi,120)
回复
pbsql 2005-02-25
insert into 另一个表(bianhao,pv)
select bianhao,pv=sum(pv) from h_order group by bianhao,convert(varchar(10),riqi,120)
回复
子陌红尘 2005-02-25
insert into 汇总表(bianhao,pv)
select
bianhao,
sum(pv)
from
h_order
where
riqi between cast('2005-01-01 00:00:00' as datetime)
and cast('2005-01-02 00:00:00' as datetime)
group by
bianhao
回复
hsj20041004 2005-02-25
zarge(鲨去来兮) 的正确 你的问题就是一个分组!!!
回复
zarge 2005-02-25
select bianhao, sum( pv ) as pv
from h_order
where riqi between '2005-01-01 00:00:00' and '2005-01-02 00:00:00'
group by bianhao
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告