我想在sql server200中查询为 [英] i want query in sql server200 as
本文介绍了我想在sql server200中查询为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
Hi all,
I have one query and it''s out put is like this.
My database in SQL Server -2000 .
Select Name from table_name
Out Put
========
Name
======
Test1
Test2
Test3
Test4
But I want this types of out put.
Out Put
========
ID Name
=========
1 Test1
2 Test2
3 Test3
4 Test4
谢谢
Thanks
推荐答案
如果ID是表中的字段,则:
If the Id is a field in the table then:
Select Id, Name from table_name
如果您想在结果中使用行号,并且行号是根据名称顺序定义的,那么查询将类似于:
If you mean that you want a row number in the result and the row number is defined based on the order of names then the query would look something like:
select row_number() over (order by name) as id, Name from table_name
开始,您只需添加列ID并将其自动递增即可.
然后编写此查询:
you just add a column ID and make it to auto-increment.
then write this query:
<br />
Select ID,Name from table_name
希望对您有所帮助:)
hope it helps :)
,如果您要查找具有按数字递增顺序的存储值.那么您可以使用IDENTITY
,如下所示
if you are looking for store values with corresponding increasing order by number. then you can useIDENTITY
as shown given below
create table Table_Name(ID int IDENTITY(1,1),Name varchar(10))
在您插入了您在Test4中提到的Test1或其他值之后,它会根据您的需要进行分配.
After inserting values as you mentioned Test1 to Test4 or something else it will give out put as you want.
这篇关于我想在sql server200中查询为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文