天大的疑问,有朋友遇到类似的问题吗?有的话,还请不吝赐教啊!!!在线等待,谢谢
select max(t.updatedate) from article t
2007-3-9 1:27:35
select top 10 t.updatedate from article t order by updatedate desc
2007-3-9 1:27:35
2007-3-9 1:27:06
2007-3-9 1:26:56
2007-3-9 1:26:26
2007-3-9 1:26:11
2007-3-9 1:26:00
2007-3-9 1:25:42
2007-3-9 1:25:28
2007-3-9 1:25:16
2007-3-9 1:24:50
而实际上表中是有比这个日期大的数据
(2007-3-23 9:33:18)
请专家,高手替俺分析分析,在此谢谢了,
同时,奉献100分,小小意思,不成敬意!
------解决方案--------------------try:
select top 10 t.updatedate from article t order by cast(updatedate as datetime) desc
------解决方案--------------------updatedate是不是日期型?,如果是字符型,这么查询
select max(CAST(t.updatedate AS DATETIME)) from article t
select top 10 t.updatedate from article t order by CAST(t.updatedate AS DATETIME) desc
------解决方案--------------------updatedate 是字符串型?
select top 10 t.updatedate from article t order by cast(updatedate as datetime) desc
------解决方案--------------------不可能吧。
------解决方案--------------------估计在楼主的表中,日期字段是字符类型的,按照字符数据排序规则的排序结果自然是错的,转为日期数据类型就正常了。
------解决方案--------------------drop table article
create table article(updatedate datetime)
insert into article
select '2007-3-9 1:27:35 '
union all select '2007-3-9 1:27:06 '
union all select '2007-3-9 1:26:56 '
union all select '2007-3-9 1:26:26 '
union all select '2007-3-9 1:26:11 '
union all select '2007-3-9 1:26:00 '
union all select '2007-3-9 1:25:42 '
union all select '2007-3-9 1:25:28 '
union all select '2007-3-9 1:25:16 '
union all select '2007-3-9 1:24:50 '
union all select '2007-3-23 9:33:18 '
select max(t.updatedate) from article t
------------------------------------------------------
2007-03-23 09:33:18.000
(所影响的行数为 1 行)
select top 10 t.updatedate from article t order by updatedate desc
updatedate
------------------------------------------------------
2007-03-23 09:33:18.000
2007-03-09 01:27:35.000
2007-03-09 01:27:06.000
2007-03-09 01:26:56.000
2007-03-09 01:26:26.000
2007-03-09 01:26:11.000
2007-03-09 01:26:00.000
2007-03-09 01:25:42.000
2007-03-09 01:25:28.000
2007-03-09 01:25:16.000
(所影响的行数为 10 行)
------解决方案--------------------updatedate 这列到底是啥类型啊
------解决方案--------------------经测试不会出现楼主说的问题