如何获取数据库中任何列的行号? [英] How can I get row number of any column in our database ?

查看:145
本文介绍了如何获取数据库中任何列的行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我想访问一个特定的字段,我想在我们的数据库中获取特定列的ROW编号

请给我答案



我尝试过:



从学生

Actually I want to access a particular Field and I want to get ROW number of a particular Column in our database
Please give me the Answer

What I have tried:

Select ROW_Number() Over(Name) from Student

推荐答案

我认为您不能在任何有效的SQL查询中直接执行此操作并且实际获得有效的响应 - 因为列索引可以轻松地更改表是定义的 - 没有应用它周围的黑客。此外,它没有任何意义,为什么不是 column_name



对于 SELECT 语句,您需要传递列名或通配符。返回数据后,您可以按索引读取列。这可以通过任何SQL阅读器来完成,例如SQL Server的C#对象或MySQL的其他类似对象。



但在此之前,我认为这是不可能的。只有少数区域允许您使用序数值或列; ORDER BY 子句等。



在CodeProject上有一个类似的问题,你可能想尝试一下, [已解决] SELECT列按列索引NOT by columnname! [ ^ ]
I do not think you can directly do that in any valid SQL query and actually get a valid response — because column-indexes can easily change due to the way that a table is defined — without applying a hack around it. Also, it doesn't make any sense, why not the column_name?

For the SELECT statement, you need to either pass the column names or the wildcard. Once the data has been returned, you can read the column by index. That can be done through any SQL reader, such as C# objects for the SQL Server or other similar for MySQL.

But before that, I don't think that is possible. Only a few of the areas permit you to use an ordinal value or the column; ORDER BY clause etc.

There is a similar question on CodeProject you might want to try that, [Solved] SELECT columns by column-index NOT by columnname![^]


SELECT      C.ORDINAL_POSITION
FROM        INFORMATION_SCHEMA.COLUMNS AS C
WHERE       C.TABLE_NAME = 'TableName'
        AND C.COLUMN_NAME = 'Password'


这篇关于如何获取数据库中任何列的行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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