要求显示纪录 当天纪录随机排序,非当天纪录按最近时间排序
-----------------------------------
例: 表A
-----------------------------------
ID Name pubtime
1 赵大 2008-06-16
2 钱二 2008-06-16
3 张三 2008-06-16
4 李四 2008-06-01
5 王五 2008-06-02
6 杨六 2008-05-16
...
-----------------------------------
查询结果就应该是:
赵大,钱二,张三为当天纪录,随机排序;
李四,王五,杨六非当天纪录,按时间排,应该是王五,李四,杨六
-----------------------------------
存储过程,视图都可以,查询语句都可以 实现就好~
-----------------------------------
例: 表A
-----------------------------------
ID Name pubtime
1 赵大 2008-06-16
2 钱二 2008-06-16
3 张三 2008-06-16
4 李四 2008-06-01
5 王五 2008-06-02
6 杨六 2008-05-16
...
-----------------------------------
查询结果就应该是:
赵大,钱二,张三为当天纪录,随机排序;
李四,王五,杨六非当天纪录,按时间排,应该是王五,李四,杨六
-----------------------------------
存储过程,视图都可以,查询语句都可以 实现就好~
解决方案 »
- 如果用正则获取想用的内容
- 可能是进度条的问题,高手帮我SEE SEE
- 求一段js代码
- 服务器脚本标记中不允许出现服务器包含文件!?
- 求SqlDataSource填充dataset的方法,谢谢!~~
- Ajax.pro 与 Atlas可以在同一个页面使用吗?
- 一般系统后台管理界面,左边的那个树型分类菜单是用什么方法做的??(这里不讨论使用现成控件)
- 目前那些开源项目中用到了EnterPrise Library???高手支持!!!
- AppLibrary 导出excel,列字符超过255会被截断
- 关于“如何控制datagrid里编辑功能出现的TextBox的宽度?”那个集锦里面怎么找不到?
- gridview 全选 不刷新页面
- 怎么用javascript对textbox的enabled设置为false
declare @table1 table
(
id INT IDENTITY,
[name] varchar(50),
pubtime varchar(50)
)insert into @table1 ([name],pubtime)
values('name1','2008-06-16 ')insert into @table1 ([name],pubtime)
values('name2','2008-06-16 ')insert into @table1 ([name],pubtime)
values('name3','2008-06-16 ')insert into @table1 ([name],pubtime)
values('name4','2008-06-01 ')insert into @table1 ([name],pubtime)
values('name5','2008-06-02 ')
select * from @table1 order by pubtime desc,newid()
SELECT * FROM 表A ORDER BY pubtime DESC, NEWID()
union
select * from b where convert(varchar,pubtime,112)<convert(varchar,getdate(),112) order by pubtime desc
能将下你那实现的原理吗。最后的查询!!!!谢谢
(
id INT IDENTITY,
[name] varchar(50),
pubtime varchar(50)
)insert into table1 ([name],pubtime)
values('name1','2008-06-16 ')insert into table1 ([name],pubtime)
values('name2','2008-06-16 ')insert into table1 ([name],pubtime)
values('name3','2008-06-16 ')insert into table1 ([name],pubtime)
values('name4','2008-06-01 ')insert into table1 ([name],pubtime)
values('name5','2008-06-02 ')
select [name],'今天' as dt from table1 where pubtime=convert(nvarchar(10),'2008-06-16') group by [name] --将'2008-06-16'换成现在的时间
union all
select [name],'以前' as dt from table1 where pubtime!=convert(nvarchar(10),'2008-06-16') group by [name] --将'2008-06-16'换成现在的时间
drop table table1
guid 就是说随即。!?
(
id INT IDENTITY,
[name] varchar(50),
pubtime varchar(50)
)insert into table1 ([name],pubtime)
values('name1','2008-06-16 ')insert into table1 ([name],pubtime)
values('name2','2008-06-16 ')insert into table1 ([name],pubtime)
values('name3','2008-06-16 ')insert into table1 ([name],pubtime)
values('name4','2008-06-01 ')insert into table1 ([name],pubtime)
values('name5','2008-06-02 ')declare @today nvarchar(1000)
declare @before nvarchar(1000)set @today=''
set @before=''
select @today=@today+[name]+',' from table1 where pubtime=convert(nvarchar(10),'2008-06-16')
print(@today)set @before=''
select @before=@before+[name]+',' from table1 where pubtime!=convert(nvarchar(10),'2008-06-16')
print(@before)drop table table1
我个人感觉,前辈您这用法是无法在实际SQL中使用的。因为数据库存储的不一定是LZ的那种时间格式。通常都是含有具体几分几秒的。前辈这用法用的太有局限性。