篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL内部连接与子查询与CTE相关的知识,希望对你有一定的参考价值。
-- Database : AdventureWorks2014
-- Get All Product Names with ListPrice similar
-- to that of the Product 'LL Mountain Seat Assembly'
-- USING A NORMAL INNER JOIN
SELECT P1. Name
FROM Production.Product AS P1
JOIN Production.Product AS P2
ON P1.ListPrice = P2.ListPrice
WHERE P2. Name = 'LL Mountain Seat Assembly';
-- USING SIMPLE SUB QUERY
-- WHERE = (Scalar Subquery)
SELECT P.Name
FROM Production.Product P
WHERE P.ListPrice = (SELECT ListPrice
FROM Production.Product
WHERE Name = 'LL Mountain Seat Assembly');
--- USING CTE (COMMON TABLE EXPRESSION)
WITH LP (ListPrice)
AS (SELECT ListPrice
FROM Production.Product
WHERE Name = 'LL Mountain Seat Assembly')
SELECT P.Name
FROM Production.Product P
WHERE P.ListPrice = (SELECT ListPrice
FROM LP);
以上是关于sql MS SQL内部连接与子查询与CTE的主要内容,如果未能解决你的问题,请参考以下文章