34,590
社区成员
发帖
与我相关
我的任务
分享
/*
--比如要排在第一位这条记录的A字段是唯一的(和其他字段不一样),这个值比如是'max',
那么在newid()前加一个排序规则,如下所示
*/
order by case when A='mzx' then 0 else 1 end,newid()
select * from
(select top 10 * from tablename order by id) aa
order by newid()
select top 100 percent * from tb order by id
union all
select top 100 * from ta order by ida
select 4 as a union all
select 3 union all
select 1 union all
select 7 union all
select 2 union all
select 5 order by a
/*
a
-----------
1
2
3
4
5
7
*/
select 1 as a ,'01' as b
union
select 2,'02' order by a desc