站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题这句SQL语句如何才能实现?

这句SQL语句如何才能实现?

摘要: 这句SQL语句如何才能实现?


表结构:
create table myTable (
starttime datetime not null,
times int not null
)
========================================================
starttime显示的时间格式为2006-11-16 10:00:00,我想按2006-11-16这样的时间格式来分组统计times的累加,我试过了,但出现错误问题.

select convert(char(10),starttime,120),sum(times) from myTable
group by convert(char(10),starttime,120)

只要加入group by convert(char(10),starttime,120)就会出错,但不加又无法正确统计,因为我要忽略时分秒进行统计的.请问怎么办????


嘛数据库?


为什么在这里转换,用jstl标签在显示的时候就可以转换,还非常简单!


补充:
这样简单的统计是没有错的,我只是为举个例子,没想到我试后没有错.我真正要实现的是复合查询,这时才会出现我所说的错误.
select convert(char(10),STARTTIME,120) as STARTTIME,(select count(1) from myTable a where a.STARTTIME=c.STARTTIME) as CALLTIMES,(select sum(SERVICETIME) from myTable b where b.STARTTIME=c.STARTTIME) as SERVICETIME from myTable c
group by convert(char(10),STARTTIME,120)
就是这句,另group by就出错.


select substring(starttime,1,10),),sum(times) from from myTable
group by substring(starttime,1,10)
这样不行吗?


select substring(starttime,1,10),),sum(times) from myTable
group by substring(starttime,1,10)



select convert(char(10),STARTTIME,120) as STARTTIME,(select count(1) from myTable a where a.STARTTIME=c.STARTTIME) as CALLTIMES,(select sum(SERVICETIME) from myTable b where b.STARTTIME=c.STARTTIME) as SERVICETIME from myTable c
group by STARTTIME
??



MSSQL数据库.
datetime类型不能用substring的.
我的意思是,要以年月日来统计,忽略时分秒,如果不转换,就把时分秒不一样但日期一样的记录也分组了呀.


查询字段清单里面不能有不在group by里面的字段


我改了下,行了.
select convert(char(10),STARTTIME,120) as STARTTIME,count(1) as CALLTIMES,sum(SERVICETIME) as SERVICETIME from XX_FLOWBILL
group by convert(char(10),STARTTIME,120)

就是不用(select...)这样的方式.晕死.

谢谢大家的热情帮助,分不多,一人将就点吧.


↑返回目录
前一篇: eclipse的项目路径问题?结题给分!
后一篇: 问个session传值问题