????????????????????????????????????????????????????????????????????????????????????????????????з?????????????????SQL???????????????????????????????????????Щ???????????????????????????????飬???????????????????????????????????????Books Online??

????1??????????????????

????????????????????????????????????????????С?SQL??ORDER BY????????????????????????????????????????????????????????????????????????????????????顣ORDER BY???????????????????????????

????2?????з?????????

???????????????????????????????????????м??????????????Χ?????????????????????????м????GROUP BY???????????????????????????磬?????????е?GROUP BY?????????????????????????????zip?????С?
SELECT ZIP FROM Customers GROUP BY ZIP

???????????GROUP BY??SELECT??乲????????Щ????????仰???SELECT?б????????GROUP BY?б?????????????????SELECT?б???????????????GROUP BY?????????t??????????????????GROUP BY??????????????????????????鰴????????????????У???????ORDER BY?????????GROUP BY????в???????????????????Ρ???????????????????????????????????????????С?

????3???????????????????

???????????????WHERE?????????GROUP BY???÷????е?????????磬???????????????????????ZIP?????С?
SELECT ZIP FROM CustomersWHEREState = 'KY' GROUP BY ZIP

??????????????WHERE???????GROUP BY???????????????????????GROUP BY????????WHERE????????????????

????4?????????з???

???????????WHERE???????????????????????????????????Щ?????????????鶨?嵫????????????????????????????????????С?????????????а???????????????????ALL????????WHERE???????????á????磬???????????????????ALL???????е?ZIP???飬???????????????????Щ??
SELECT ZIP FROM CustomersWHEREState = 'KY' GROUP BY ALL ZIP 

????????????????????????????????????????????????ù????ALL????????t???????????????????ALL????????????????磬??????????????????????ZIP?е????????????????????????ZIP???
SELECT ZIP?? Count(ZIP) AS KYCustomersByZIP FROM 
CustomersWHEREState = 'KY' GROUP BY ALL ZIP 

??????????????????????е?????ZIP??????????????Щ???????????ZIP?????????(KYCustomersByZIP)???????0????????????GROUP BY ALL??

????5?????????????

????WHERE?????GROUP BY????????м??????????????????????????????????HAVING??????????£?WHERE????HAVING????????????????????????????????????????????????????????????????????????????WHERE?????????????HAVING????????顣

??????????????????HAVING???????????????????????顣???磬???????????????ZIP?????У???????????????????????????е?ZIP??

SELECT ZIP?? Count(ZIP) AS CustomersByZIP FROM

Customers GROUP BY ZIP HAVING Count(ZIP) = 1

?????????Щ?????λ???????????????С?