易截截图软件、单文件、免安装、纯绿色、仅160KB

mssql 时间比较问题

数据库结构:
        id      hit      times
1 1 2008年2月19日
2 26 2008年2月27日
3 32 2008年2月27日

select sum(hit)as wk,times from hit where id=1005 group by times
得到结果:
1 2009年12月10日
2 2009年12月16日
1 2009年12月17日
1 2009年12月19日
983 2009年12月1日
1262 2009年12月2日
1201 2009年12月3日
857 2009年12月4日
951 2009年12月5日
924 2009年12月6日
312 2009年12月7日
4 2009年12月8日
2 2009年12月9日


select sum(hit)as wk,times from hit where id=1005 and replace(replace(replace(times,'年','-'),'月','-'),'日','')>=replace(replace(replace('2009年12月20日','年','-'),'月','-'),'日','') group by times
得到结果:
1201 2009年12月3日
857 2009年12月4日
951 2009年12月5日
924 2009年12月6日
312 2009年12月7日
4 2009年12月8日
2 2009年12月9日

奇怪为何最后的语句会得到这样的结果?求高人指点。。



你REPLACE完了是不是应该用CONVERT转一下再比较。。。

SQL code:
select sum(hit)as wk,times from hit where id=1005 and CONVERT(DATETIME,replace(replace(replace(ti


相关问答:

如何将excel中的数据实时保存至mssql数据库?

假设有两张表,t1 t2
t1:id 字段1 字段2 字段3
t2:id 字段4 字段5 字段6

现用一条查询语句select t1.*,t2.* from t1,t2 where t1.id=t2.id and 条件……
将符合条件的数据从mssql数据库中导出至exce ......

招聘MsSQL DBA - 上海

有意者请联系yushan-33@hotmail.com / 18821146311

Microsoft SQL Administrator

Job Description:

A detail oriented Microsoft SQL Administratorwith excellent problem solving, analyti ......

MSSql数据库被挂马

现有一个ASP+mssql的网站,被挂马了,将里面一个表中的ntext字段挂马挂马,“<script src=http://木马地址></script>”,的方式是,不断地修改该字段的值,直接加在最后的,时间长了,可以看到该字段中有 ......

mssql安全问题

我做了一个网站,其中使用了一个存储过程,下面的是调用存储过程的代码
Set MyComm = CreateObject("ADODB.Command")
with MyComm
.ActiveConnection = cn 'MyConStr是数据库连接字串
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号