Ê×Ò³ > Êý¾Ý¿â > SQL Server > ÕýÎÄ
SQL²éѯ³õѧÕßÖ¸Ä϶ÁÊé±Ê¼Ç(ËÄ)where´Ó¾ä
2015-06-03       ¸öÆÀÂÛ    À´Ô´£ºsoliddream66µÄרÀ¸  
ÊÕ²Ø    ÎÒҪͶ¸å

CHAPTER6 Filtering Your Data

±¾Õ½éÉÜWHERE´Ó¾ä.

predicates

Comparison,BETWEEN,IN, LIKE, and IS NULL.

We¡¯ll cover theother two¡ªQuantified and EXISTS¡ªin Chapter 11, Subqueries.

Comparison

Equality and Inequality

= ,<>

Less Than and Greater Than

<,>

less than or equal to

<=

greater than or equal to

>=

combinecomparisons using AND and OR

Range

\

TheBETWEEN . . . AND predicatedefines the range by using the value of the second value expression

as the start pointand the value of the third value expression as the end point.

Both the start pointand end point are part of the range.

ϰ¹ßʹÓà (Value Expression1 <= ValueExperssion2) and (Value Expression1 >= Value Experssion3)µÄ¸÷λͬѧ,¿ÉÒÔ¿¼ÂÇʹÓÃBETWEEN . . . ANDÌæ´ú,ÕâÑùSQLÓï¾ä»á¸üÈÝÒ×ÔĶÁÀí½â.<†·Ÿ"/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHAgbGFuZz0="en-US">

Set Membership

\

Pattern Match

\

Apattern string can consist ofany logical combination of regular string characters and

two special wildcardcharacters: the percent sign (%) and the underscore (_).

Thepercent sign represents zero or more arbitrary regular characters, and the underscore represents a single arbitraryregular character.

%Óë_ͨÅä·ûÀà似ÓÚÕýÔò±í´ïʽÖеÄ*Óë?

Óöµ½Í¨Åä·ûÓëÕý³£×Ö·û»ìÏýµÄÇé¿öÔõô°ì?±ÈÈçÎÒÃÇÐèҪƥÅ京ÓÐÏ»®ÏßµÄ×Ö·û´®Ôõô°ì?ÕâÒ²Êǹ¦ÄÜ×Ö·û°üº¬ÔÚ³£¹æ×Ö·û»áÓöµ½µÄ»ìÏýÇé¿ö,±àÂëÖо­³£Åöµ½.ÕâʱÎÒÃÇÐèÒª½«¹¦ÄÜ×Ö·ûתÒåΪ³£¹æ×Ö·û,ÎÒÃÇʹÓÃESCAPE¹Ø¼ü×ÖʵÏÖÕâ¸ö¹¦ÄÜ.

¾Ù¸öÀý×Ó,һĿÁËÈ»:

¡°Showme a list of products that have product codes beginning with ¡®G_00¡¯ and ending in a single number orletter.¡±

SQL SELECT ProductName, ProductCode

FROMProducts

WHEREProductCode LIKE 'G\_00_' ESCAPE '\'

Keep in mind thatthe character you use as an escape character should not be

part of the valuesyou¡¯re trying to retrieve.

Null

\

ÅжÏValue ExpressionÊÇ·ñΪNULLµÄʱºòÇ벻ҪʹÓÃValue Expression = NULL,ÕâÊdz£·¸µÄС´íÎó.

Excluding Rows with NOT

Order of Precedence

\

Whenyou treat a combined set of conditions as a single unit, by definitionit becomes a

searchcondition, and you must enclose it in parentheses.

Ìí¼ÓÀ¨ºÅÒÔ±ÜÃâ¿ÉÄܵĻìÏý.

Whenyou need to use multiple conditions, make certain that the condition thatexcludes the

most rows from theresult set is processed first so that your database can

potentially find theanswer faster.


µã»÷¸´ÖÆÁ´½Ó ÓëºÃÓÑ·ÖÏí!»Ø±¾Õ¾Ê×Ò³
ÉÏһƪ£ºSQL²éѯ³õѧÕßÖ¸Ä϶ÁÊé±Ê¼Ç(Îå)¼¯ºÏ²Ù×÷Óë¶à±í²éѯ½éÉÜ
ÏÂһƪ£ºSQL²éѯ³õѧÕßÖ¸Ä϶ÁÊé±Ê¼Ç(Èý)Öµ±í´ïʽ½éÉÜ
Ïà¹ØÎÄÕÂ
ͼÎÄÍÆ¼ö
ÎÄÕÂ
ÍÆ¼ö
µã»÷ÅÅÐÐ

¹ØÓÚÎÒÃÇ | ÁªÏµÎÒÃÇ | ¹ã¸æ·þÎñ | Ͷ×ʺÏ×÷ | °æÈ¨ÉêÃ÷ | ÔÚÏß°ïÖú | ÍøÕ¾µØÍ¼ | ×÷Æ··¢²¼ | Vip¼¼ÊõÅàѵ
°æÈ¨ËùÓÐ: ºìºÚÁªÃË--ÖÂÁ¦ÓÚ×öʵÓõÄIT¼¼ÊõÑ§Ï°ÍøÕ¾