An additional column of serial numbers is automatically added to the SQL statement query results, and an SQL column is automatically added.

Source: Internet
Author: User

An additional column of serial numbers is automatically added to the SQL statement query results, and an SQL column is automatically added.

Sqlserver

It can be implemented using the row_number function.

As follows:

SELECT *, row_number () OVER (order by score (column name) DESC) AS rank FROM score


The SQL query statement automatically adds the serial number.

SQL 2000 has been written; similar, but forget, there are two solutions for reference:
1. select identity (INT, 1, 1) AS No., avge FROM Table1
2. select identity (INT, 1, 1) AS No., avge INTO # temp1 FROM Table1
SELECT * FROM # temp1
Drop table # temp1

The above two types are purely handwritten. If any word is wrong, please forgive me.

(Sqlserver) How to Write an SQL statement that adds an auto-increment column when the query result is inserted into a new table?

Assume that the table has a primary key ID column. The following table generates a new table with an Sequence Number Column greater than the original table and is filled with the ID number.
Select No. = (select count (1) from tablename a where a. id> = tablename. id), * from tablename

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.