sql排序问题?
t(id,name)id为int,不自动增长,不是主键,可以重复
有如下数据
id name
3 哈哈
2 士大夫
565 士大夫1
现要排序,倒序(从最后一条记录开始取几条数据),如何排,即取最后几条记录
SQL code:
N-M条记录
1.
select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
2.
select top n * from
(select top m * from tablename order by columnname) a
order by columnname desc
3.
如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename
取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m
如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
4.
如果表里有identity属性,那么简单:
select * from tablename where identitycol between n and m
SQL code:
select top 10 from table order by ID Desc
???
给出的条件,不充分啊!
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
相关问答:
请问一下,外网两台SQLSERVER实例数据传输,有没有采用数据压缩和加密。压缩比是多少,加密是什么加密算法?相关文档哪里可以找到?谢谢
我也想知道!关注此贴!
关注~~
数据库大牛都哪去了啊?
......
我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
--drop table #T1
--drop table #T2
create Table #T1(ID int,
QueryID nvarchar(20),
ResultID1 nvarchar(20),
ResultID2 nvarchar(20))
create Table #T2(SortNo int,
QueryID nvarchar(20),
ResultID1 nv ......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......