在视图中创建一个计算列。可能吗? [英] Creating a computed column in a View. Is it possible?
本文介绍了在视图中创建一个计算列。可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的SQL视图返回以下内容
My SQL view returns the following
ID Name
AA Gina
AB George
AC John
我想添加一个计算列 UpCounter
,因此我的视图返回类似
I would like to add a computed column UpCounter
so my view returns something like
ID Name UpCounter
AA Gina 1
AB George 2
AC John 3
有可能吗?
更新:UpCounter实际上是行索引
UPDATE: The UpCounter is actually the row index
推荐答案
请参见< a href = http://msdn.microsoft.com/en-us/library/ms189461.aspx rel = nofollow>覆盖子句。
SELECT ID, Name, ROW_NUMBER() OVER(ORDER BY ID ASC) AS UpCounter
FROM xyz
这里是一个用例:
WITH x AS (
SELECT 'AA' as ID, 'Gina' as Name
UNION
SELECT 'AB' as ID, 'George' as Name
UNION
SELECT 'AC' as ID, 'John' as Name
)
SELECT ID, Name, ROW_NUMBER() OVER(ORDER BY ID ASC) AS UpCounter
FROM x
这篇关于在视图中创建一个计算列。可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文