SQL Server join - 工作澄清

时间:2015-12-10 05:58:25

标签: sql-server

任何人都可以解释为什么其中一个连接只是以逗号分隔?这样使用它有什么好处吗?该连接的含义是什么,如何通过将该连接拆分为普通连接来重写查询?

select distinct 
    aspl.AssessmentId, TestingProviderId, aspl.AssessmentSubjectId, 
    ep.providername, asplg.PerformanceLevelId as PerformanceLevelId, 
    asplg.PerformanceLevelName, asplg.PerformanceLevelColorARGB, 
    null as PerformanceLevelIdCount, null as GroupTotalCount, 
    null as PercentOfGroup, aspl.LastLoadTime 
from 
    AssessmentStudentPerformanceLevel aspl
inner join 
    AssessmentStudentImported asi on aspl.AssessmentStudentCode = asi.AssessmentStudentCode
inner join 
    EducationProvider ep on asi.testingepid=ep.providerid 
left join 
    Student stu on asi.MappedStudentId = stu.StudentId, 
    AssessmentPerformanceLevelGeneric asplg
where 
    aspl.AssessmentId = asplg.AssessmentId 
    and aspl.testingproviderid = ep.providerid 
    and ((IsNull(null, 0) = 0) or (ep.providerid = null))
    and ((IsNull(0, 0) = 0) or (ep.providerlevelid = 0))
    and aspl.AssessmentId = 239012015 
    and aspl.assessmentsubjectid = 1 
order by 
    aspl.AssessmentId, aspl.AssessmentSubjectId, 
    ep.providername, asplg.PerformanceLevelId

在上面的查询中,我提到了这一部分

 left join 
     Student stu on asi.MappedStudentId = stu.StudentId, 
     AssessmentPerformanceLevelGeneric asplg

1 个答案:

答案 0 :(得分:1)

AssessmentPerformanceLevelGeneric是一个asplg是别名的表。

逗号','条件是内连接,没有条件是交叉连接。

SELECT *
FROM A
INNER JOIN B
ON <condition>
=
SELECT *
FROM A, B
WHERE <condition>


SELECT *
FROM A
CROSS JOIN B
=
SELECT *
FROM A, B