求一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

谢谢
...全文
111 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧