http://sqlblog.com/blogs/adam_machanic/archive/2008/04/22/sql-server-query-processing-puzzle-like-vs.aspx
这个是一个sql牛人的 博客,他在上面提出了一个小问题:
USE TempDB
GO
CREATE TABLE b1 (blat1 nCHAR(5) NOT NULL)
CREATE TABLE b2 (blat2 VARCHAR(200) NOT NULL)
GO
INSERT b1
SELECT LEFT(AddressLine1, 5) AS blat1 FROM AdventureWorks.Person.Address
INSERT b2
SELECT AddressLine1 AS blat2
FROM AdventureWorks.Person.Address
GO
GO
CREATE TABLE b1 (blat1 nCHAR(5) NOT NULL)
CREATE TABLE b2 (blat2 VARCHAR(200) NOT NULL)
GO
INSERT b1
SELECT LEFT(AddressLine1, 5) AS blat1 FROM AdventureWorks.Person.Address
INSERT b2
SELECT AddressLine1 AS blat2
FROM AdventureWorks.Person.Address
GO
然后执行如下的查询语句:
SELECT * FROM b1
JOIN b2 ON b2.blat2 LIKE b1.blat1 + '%'
JOIN b2 ON b2.blat2 LIKE b1.blat1 + '%'