SELECT * FROM SalesHistory
WHERE EXISTS(SELECT NULL)
SELECT * FROM SalesHistory
WHERE 1 = 1
SELECT * FROM SalesHistory
WHERE EXISTS(SELECT 1)
在刚才的脚本中,你可能会对下面的语句感到迷惑:
SELECT * FROM SalesHistory
WHERE EXISTS(SELECT NULL)
SELECT * FROM SalesHistory sh
WHERE EXISTS
(
SELECT AVG(SalePrice)
FROM SalesHistory shi
HAVING AVG(SalePrice) > sh.SalePrice
)
SELECT * FROM SalesHistory sh
WHERE SalePrice <
(
SELECT AVG(SalePrice)
FROM SalesHistory shi
)
IF EXISTS
(
SELECT * FROM SalesHistory
WHERE SaleDate = '1/1/2001' AND
Product = 'Computer' AND
SalePrice = 1000
)
UPDATE TOP(1) SalesHistory
SET SalePrice = 1100
WHERE SaleDate = '1/1/2001' AND
Product = 'Computer' AND
SalePrice = 1000
ELSE
INSERT INTO SalesHistory
(Product, SaleDate, SalePrice)
VALUES
('Computer', '1/1/2001', 1100)