 示例8-1
 
 SELECT Bookid,bookName,Price  FROM BookInfo 
WHERE Price >
(SELECT AVG(price) FROM BookInfo)

示例8-2
SELECT BookID,BookName,publishDate,PublisherID  FROM BookInfo 
WHERE PublisherID =(SELECT publisherID FROM BookInfo WHERE BookName ='JavaWeb开发技术详解') 
AND YEAR(PublishDate) = 
( SELECT  YEAR(publishDate) FROM BookInfo WHERE BookName ='JavaWeb开发技术详解' )

示例8-4
SELECT  BookID ,BookName ,Author,Price  FROM BookInfo 
WHERE Price >ALL(SELECT Price FROM BookInfo WHERE CategoryID =
(SELECT categoryid FROM Category  WHERE CategoryName ='JAVA')
)

示例8-5
SELECT BookID ,BookName ,Price ,CategoryID  
FROM BookInfo  a 
WHERE a.Price =
      (
      SELECT max(b.price)  
      FROM BookInfo b 
      WHERE a.CategoryID =b.CategoryID
    )
示例8-6
  SELECT BookID,BookName,Author 
FROM BookInfo WHERE EXISTS
(
SELECT * FROM SalesDetails 
WHERE BookID=BookInfo.BookID
)

示例8-7
 SELECT a.UserId,a.UserName,YEAR(a.hiredate)  '入职年份'
FROM UserInfo a WHERE NOT EXISTS 
(
SELECT * FROM SalesMaster b WHERE b.UserID=a.UserID
)

示例8-8
SELECT  BookID ,BookName,Author,PublisherID   FROM BookInfo  WHERE PublishERID=(SELECT PublisherID FROM Publisher WHERE PublisherName ='机械工业出版社')
UNION  
SELECT  BookID ,BookName,Author,PublisherID   FROM BookInfo  WHERE PublishERID=(SELECT PublisherID FROM Publisher WHERE PublisherName ='人民邮电出版社')

示例8-9
 SELECT '009' AS 用户ID,'张三' as 用户名, '男' as 性别, 20 as 年龄
UNION 
SELECT  UserID ,UserName,Sex,Age  FROM  UserInfo
