【问题标题】:What is the 't' mean at end of the subquery in SQL ServerSQL Server 中子查询末尾的“t”是什么意思
【发布时间】:2018-11-15 16:04:49
【问题描述】:

我有以下代码用于按行和起点查询数据:

SELECT InquiryId
FROM (select InquiryId,  ROW_NUMBER() over (order by InquiryId) as Seq 
from [InquiryTable] WITH(NOLOCK)
where InquiryId >= 100 and InquiryId <= 200)t
where Seq Between 1 and 20

SQL server 中第四行末尾的字符 't' 是什么意思?

谢谢

【问题讨论】:

标签: sql sql-server subquery


【解决方案1】:

这是一个有用的视觉效果,展示了t 是如何成为别名的:

SELECT *
FROM table t

用子查询替换table

SELECT *
FROM (SELECT * FROM table) t

【讨论】:

    【解决方案2】:

    它是您的子查询的别名。改进的缩进有助于您更好地理解:

    SELECT InquiryId
    FROM (select InquiryId,  ROW_NUMBER() over (order by InquiryId) as Seq 
          from [InquiryTable] WITH(NOLOCK)
          where InquiryId >= 100 
            and InquiryId <= 200
         ) AS t
    where Seq Between 1 and 20
    

    【讨论】:

      【解决方案3】:

      不代表没关系,你是renaming the table in the subquery as t,但是在from to rename中不能用as,但是必须直接用表中的名字,可以要求表的列或者子查询在你的情况下使用t.col

      【讨论】:

      • 子查询被命名为没有任何表。
      • 我已更正,但它适用于子查询和表
      • 可能是语言问题?不过,我没有看到您的回答有任何重大变化。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      相关资源
      最近更新 更多