一个棘手的sql语句

mana5116 2003-11-04 03:41:01
现在数据库表当中有abcd四列共五条记录:
a b c d
1001 zhang 8.21 2003-11-01 13:12:21.020
1002 liu 18.00 2003-11-01 13:15:51.451
1003 mkleq 2.15 2003-11-02 13:17:13.132
1004 kdlsl 16.25 2003-11-03 13:21:53.165
1005 jifes 120.45 2003-11-03 13:06:16.122

现在想按照d列中每天的日期,就是按照每天来分组,如何做?
我做了一个:
select count(*),sum(c) from table group by datepart(day,d)
只能求出某年某月1号的数据,就是说,得到的是所有1号日子的数据,
而不能按照每天来统计。
...全文
137 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuantianwen 2003-11-05
  • 打赏
  • 举报
回复
select count(*),sum(c),left(d,10) from table group by left(d,10)
sql语句中能包括left用法吗??
我在用left时为什么他提示我说需要java的什么东西
songzj8 2003-11-05
  • 打赏
  • 举报
回复
select count(*),sum(c) ,left(CAST(d AS char(22)),10)from table group by left(CAST(d AS char(22)),10);
hotxia 2003-11-05
  • 打赏
  • 举报
回复
select count(*),sum(c) from table group by left(str(d),11)
songzj8 2003-11-05
  • 打赏
  • 举报
回复
数据库是什么
heijiangff 2003-11-04
  • 打赏
  • 举报
回复
select count(*),sum(c),left(d,10) from table group by left(d,10)
有道理!
xcp077 2003-11-04
  • 打赏
  • 举报
回复
select count(*),sum(c),left(d,10) from table group by left(d,10)

因为在SQL中,DATATIME字段可以直接当成字符型来取LEFT,不会报错的,还有,以后象这种情况,D字段最好定为VARCHAR型的,有问题联系QQ:149582404,
liliang800207 2003-11-04
  • 打赏
  • 举报
回复
select count(*),sum(c) from table group by left(str(d),11)
red_bat 2003-11-04
  • 打赏
  • 举报
回复
select trunc(d),count(*),sum(c) from table group by trunc(d);
huangxinru 2003-11-04
  • 打赏
  • 举报
回复
select count(*),sum(c) from table group by convert(char(12),d);

eminena 2003-11-04
  • 打赏
  • 举报
回复
select count(*),sum(c) from table group by left(str(d),11)
mittee 2003-11-04
  • 打赏
  • 举报
回复
用下面的试一下:
select count(*),sum(c) from table group by day(d)

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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