特殊时间排序问题
时间:2011-12-19
来源:互联网
我排序的时候,按会议时间倒序排,结果显示有不太正确
大致结果:
4000-01-01
4000-01-01
4000-01-01
4000-01-01
3000-01-01
3000-01-01
3000-01-01
3000-01-01
4000-01-01
4000-01-01
3000-01-01
3000-01-01
3000-01-01
3000-01-01
3000-01-01
3000-01-01
会出现这样的情况,不知是何原因?求教!
作者: dwarf471 发布时间: 2011-12-19
作者: szstephenzhou 发布时间: 2011-12-19
if object_id('tb') is not null drop table tb go create table tb ( id int identity(1,1), name varchar(10) ) go insert into tb(name) select '4000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' go select * from tb order by case when name='3000-01-01' then 0 else 1 end desc go /* 楼主是这意思吗 id name ----------- ---------- 1 4000-01-01 2 4000-01-01 3 4000-01-01 4 4000-01-01 9 4000-01-01 10 4000-01-01 11 3000-01-01 12 3000-01-01 13 3000-01-01 14 3000-01-01 15 3000-01-01 16 3000-01-01 5 3000-01-01 6 3000-01-01 7 3000-01-01 8 3000-01-01 (16 行受影响) */
作者: pengxuan 发布时间: 2011-12-19
按理应该显示
4000-01-01
4000-01-01
3000-01-01
3000-01-01
3000-01-01
但是我现在会如有几个4000年的时间夹杂在3000年里
不知为何!
作者: dwarf471 发布时间: 2011-12-19
if object_id('tb') is not null drop table tb go create table tb ( id int identity(1,1), name varchar(10) ) go insert into tb(name) select '4000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' go select * from tb order by name id name ----------- ---------- 5 3000-01-01 6 3000-01-01 7 3000-01-01 8 3000-01-01 11 3000-01-01 12 3000-01-01 13 3000-01-01 14 3000-01-01 15 3000-01-01 16 3000-01-01 9 4000-01-01 10 4000-01-01 1 4000-01-01 2 4000-01-01 3 4000-01-01 4 4000-01-01 (16 行受影响)
作者: szstephenzhou 发布时间: 2011-12-19
还有你的时间列是字符型的么?
作者: fredrickhu 发布时间: 2011-12-19
你是怎么排序的?直接order by 时间列?
还有你的时间列是字符型的么?
时间列是datetime类型的,直接按时间列倒序
SQL code
select * from tb order by time desc
作者: dwarf471 发布时间: 2011-12-19
作者: dwarf471 发布时间: 2011-12-19
其实我自建了一测试表,实验也是没问题的,但是到正式的表里,查出来就有刚才的问题
正式表数据和结构贴出来
作者: pengxuan 发布时间: 2011-12-19
declare @T table (col datetime) insert into @T select '4000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '4000-01-01' union all select '4000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' union all select '3000-01-01' select * from @T ORDER BY 1 DESC /* col ----------------------- 4000-01-01 00:00:00.000 4000-01-01 00:00:00.000 4000-01-01 00:00:00.000 4000-01-01 00:00:00.000 4000-01-01 00:00:00.000 4000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 3000-01-01 00:00:00.000 */
作者: maco_wang 发布时间: 2011-12-19
作者: qianjin036a 发布时间: 2011-12-19
CREATE TABLE [dbo].[wd_Meeting_Notice]( [BelongXiaQuCode] [nvarchar](50) NULL, [OperateUserName] [nvarchar](50) NULL, [OperateDate] [datetime] NULL, [Row_ID] [int] IDENTITY(1,1) NOT NULL, [YearFlag] [nvarchar](4) NULL, [RowGuid] [nvarchar](50) NULL, [MeetingTitle] [nvarchar](500) NULL, [MeetingDate] [nvarchar](50) NULL, [MeetingHour] [nvarchar](50) NULL, [MeetingMini] [nvarchar](50) NULL, [IfSpecific] [nvarchar](50) NULL, [MeetingBeginTime] [nvarchar](500) NULL, [Address] [nvarchar](500) NULL, [ChuXiRenY] [ntext] NULL, [HuiYi_YC] [ntext] NULL, [ReMark] [nvarchar](2000) NULL, [NoticePerson] [ntext] NULL, [NoticePersonGuid] [ntext] NULL, [SubOUName] [nvarchar](50) NULL, [LoadDate] [datetime] NULL, [ArchiveFileTypeGuid] [nvarchar](50) NULL, [ProcessVersionInstanceGuid] [nvarchar](50) NULL, [SubWebFlowOuGuid] [nvarchar](50) NULL, [BaseOuGuid] [nvarchar](50) NULL, [DelFlag] [int] NULL, [PaperGUID] [nvarchar](50) NULL, [ArchiveState] [nvarchar](50) NULL, [InitUserDisplayName] [nvarchar](50) NULL, [InitUserGuid] [nvarchar](50) NULL, [MeetingSet] [int] NULL, [txtLoadDate] [nvarchar](50) NULL, [MeetingTime] [datetime] NULL, [MeetingTimeV2] [datetime] NULL, [MeetingTimeV3] [nvarchar](100) NULL, [IsNotice] [int] NULL)

作者: dwarf471 发布时间: 2011-12-19
作者: dwarf471 发布时间: 2011-12-19
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28