读取SQL的最后一行的数据并传输到另一个SQL表 [英] Read data of last row of a SQL and transfer to another SQL table

查看:186
本文介绍了读取SQL的最后一行的数据并传输到另一个SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在最后一行读取一个sql表,其中有10个coloumns(1-10)并将5个coloumns(3-7)写入另一个行格式的表格中。



我尝试过的事情:



我是SQL的新手并尝试过很多东西文章仍然没有成功。

I wanted to read the last row a sql table which is having 10 coloumns (1-10) and write 5 coloumns (3-7) to another table of in row format in a single coloumn.

What I have tried:

I am new to SQL and have tried so many things from articles still not succeded.

推荐答案

你需要把它分成几部分。要选择最后一行,您需要确定如何识别最后一行。希望你有一个ID列,它是一个标识列,所以它非常简单。

You need to break it into parts. To select the last row you need to determine how do you identify the last row. Hopefully you have an ID column that is an identity column so then it is really easy.
SELECT TOP 1
FROM table1 
ORDER BY ID DESC





将此记录的部分内容插入另一个表格非常简单。



To insert parts of this record into another table is very easy.

INSERT INTO table2 (field1, field2, field3)
SELECT TOP 1 field3, field4, field5) -- or whatever fields you want
FROM table1
ORDER BY ID DESC


这篇关于读取SQL的最后一行的数据并传输到另一个SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆