【问题标题】:Use of Inner Join on Multiple Column Conditions vs using WHere Clause在多列条件上使用内连接与使用 WHere 子句
【发布时间】:2014-10-02 17:05:12
【问题描述】:

我有需要自我加入的表(通过行号和分区等获得) 我在哪里试图找到上次访问的时间并试图在最后平均它

我的问题是使用多个 INNER 连接条件还是使用 Where 子句更好?

原表

RN、AppId、UserId、日期时间、国家

多个内连接条件

SELECT TBL0.AppId   , TBL0.UserId, TBL0.Datetime, TBL1.Country  ,
Diff   ( TBL0.Datetime,TBL1.Datetime)    AS TimeSpans
FROM TBL AS TBL0  INNER JOIN TBL AS TBL1   
 ON TBL0.UserXuid == TBL1.UserId  AND TBL0.AppId == TBL1.AppId

 WHERE TBL0.RN -1  == TBL0.RN 

关于 Where 子句

SELECT TBL0.AppId   , TBL0.UserId, TBL0.Datetime, TBL1.Country  ,
Diff   ( TBL0.Datetime,TBL1.Datetime)    AS TimeSpans
FROM TBL AS TBL0  INNER JOIN TBL AS TBL1   
ON TBL0.UserXuid == TBL1.UserId

WHERE TBL0.RN -1  == TBL0.RN AND TBL0.AppId == TBL1.AppId

就性能等而言,哪个更好

【问题讨论】:

  • 这是MYSQL 还是SQL Server?
  • ==?我知道语法在 SQl 服务器中不起作用。

标签: mysql sql-server inner-join where-clause


【解决方案1】:

为什么不亲眼看看呢? SQL Server 有一个内置的分析工具,您可以在其中查看详细的执行计划。见here。

【讨论】:

    猜你喜欢
    • 2017-06-28
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多