SQL ²éѯ¡°½ö½ö¡±ÖÁÉÙ¡°È«²¿¡±µÄÎÊÌâ
“È«²¿µÄÎÊÌâ”ÔÚÉÏһƪÖÐÒѾд¹ýÒ»µãÁË¡£
“½ö½ö”
£ºÕâ¸öÎÊÌâ¿ÉÒÔʹÓöà±íÁ¬½ÓÀ´´¦Àí¡£ÀýÈ磺²éѯ½ö½öÑ¡ÐÞÁ˿γÌAºÍ¿Î³ÌBµÄѧÉúµÄÐÅÏ¢,sqlÈçÏ£º
ÆäÖбístudent¶¨ÒåÁËѧÉúµÄÐÅÏ¢¡£transcript¶¨ÒåÁËѧÉúµÄÑ¡¿ÎÇé¿ö¡£crscode×ֶαíʾ¿Î³Ì´úÂë¡£
select s.id
from student s,transcript t1,transcript t2
where s.id = t1.studid and t1.studid = t2.studid
and t1.crscode = 'cs305' and t2.crscode = 'mgt123'
ÕâÀïÊÇÈý¸ö±íµÄÁ¬½Ó¡£
“ÖÁÉÙ”£ºÖÁÉÙµÄÎÊÌ⣬Èç¹û
ÖÁÉÙµÄÄÚÈÝÊÇÔ¤ÏÈÖªµÀµÄ£¬È磺²éѯÖÁÉÙÑ¡ÐÞÁ˿γÌAºÍBµÄѧÉú£¬ÕâÑùÒ²ÊÇ¿ÉÒÔʹÓöà±íÁ¬½ÓµÄ¡£
sqlÈçÏ£º
select t1.studid
from transcript t1,transcript t2,student s
where t1.crscode = 'cs305' and t2.crscode = 'cs315' and s.id = t1.studid and t1.studid = t2.studid
µ«ÊÇÈç¹û
ÖÁÉÙµÄÄÚÈÝÊÂÏÈÊDz»ÖªµÀµÄ£¬¾Í²»ÄÜÓöà±íÁ¬½ÓÁË¡£È磺²éѯÖÁÉÙÑ¡ÐÞÁËѧÉúSÑ¡Ð޵Ŀγ̵ÄѧÉú¡£¾ÍÊÇ˵ѧÉúSÑ¡ÐÞÁËһЩ¿Î³Ì£¬
²é²é¿´ÄÄЩѧÉúµÄÑ¡¿ÎÖаüº¬
ÕâЩ¿Î³ÌµÄ¡£ºÜÏÔÈ»sqlÖÐûÓД°üº¬“ÕâÑùµÄν´Ê¡£µ«ÊÇ¿ÉÒÔ½«Õâ¸öÐèÇóת»»ÎªÆäËûµÄÃèÊö·½Ê½£º
²»´æÔÚÕâÑùµÄ¿Î³Ì£¬Ñ§ÉúSÑ¡ÁË£¬µ«ÊǸÃѧÉú
ûÓÐÑ¡¡£
ÕâÀïºì×ֵĔ¸ÃѧÉú“¾ÍÊÇÎÒÃÇÒª²éѯ³öÀ´µÄÄÚÈÝ¡£
sqlÈçÏ£º
Ïà¹ØÎĵµ£º
1.Ñ¡Ôñ²Ù×÷µÄÊý¾Ý¿â
Á¬½Óµ½·þÎñÆ÷Ö®ºó£¬Ê×ÏÈÐèҪѡÔñÒª½øÐвÙ×÷µÄÊý¾Ý¿â¡£Ê¹ÓÃPHPµÄMSSQLÀ©Õ¹¿âÖеÄmssql_select_db()º¯Êý¼´¿ÉʵÏÖÁ¬½Ó·þÎñÆ÷ÉϵÄÊý¾Ý¿â¡£¸Ãº¯Êý¸ñʽÈçÏ£º
bool mssql_select_db(string database_name[,resource link_identifier)
¸Ãº¯Êý¸÷²ÎÊýÒâÒ壺
a. ²ÎÊý database_nameΪָ¶¨µÄ·þÎñÆ÷ÉÏ¿ÉÓõÄÊý¾Ý ......
×Ô£ºhttp://blog.csdn.net/AJAXBloger/archive/2007/08/29/1764506.aspx
×Ó²éѯ£º
ʹÓÃ×Ó²éѯµÄÔÔò
1.Ò»¸ö×Ó²éѯ±ØÐë·ÅÔÚÔ²À¨ºÅÖС£
2.½«×Ó²éѯ·ÅÔڱȽÏÌõ¼þµÄÓÒ±ßÒÔÔö¼Ó¿É¶ÁÐÔ¡£
×Ó²é
ѯ²»°üº¬ ORDER BY ×Ӿ䡣¶ÔÒ»¸ö SELECT Óï¾äÖ»ÄÜÓÃÒ»¸ö ORDER BY ×Ӿ䣬
²¢ÇÒÈç¹ûÖ¸¶¨ÁËËü¾Í±ØÐë·ÅÔÚÖ÷
SELECT Óï¾äµÄ×î ......
×Ó²éѯ£º
ʹÓÃ×Ó²éѯµÄÔÔò
1.Ò»¸ö×Ó²éѯ±ØÐë·ÅÔÚÔ²À¨ºÅÖС£
2.½«×Ó²éѯ·ÅÔڱȽÏÌõ¼þµÄÓÒ±ßÒÔÔö¼Ó¿É¶ÁÐÔ¡£
×Ó²éѯ²»°üº¬ ORDER BY ×Ӿ䡣¶ÔÒ»¸ö SELECT Óï¾äÖ»ÄÜÓÃÒ»¸ö ORDER BY ×Ӿ䣬
²¢ÇÒÈç¹ûÖ¸¶¨ÁËËü¾Í±ØÐë·ÅÔÚÖ÷ SELECT Óï¾äµÄ×îºó¡£
ORDER BY ×Ó¾ä¿ÉÒÔʹÓ㬲¢ÇÒÔÚ½øÐÐ Top-N ·ÖÎöʱÊDZØÐëµÄ¡£
3.ÔÚ×Ó² ......
char¡¢varchar¡¢textºÍnchar¡¢nvarchar¡¢ntext
charºÍvarcharµÄ³¤¶È¶¼ÔÚ1µ½8000Ö®¼ä£¬ËüÃǵÄÇø±ðÔÚÓÚcharÊǶ¨³¤×Ö·ûÊý¾Ý£¬¶øvarcharÊDZ䳤×Ö·ûÊý¾Ý¡£Ëùν¶¨³¤¾ÍÊdz¤¶È¹Ì¶¨
µÄ£¬µ±ÊäÈëµÄÊý¾Ý³¤¶ÈûÓдﵽָ¶¨µÄ³¤¶Èʱ½«×Ô¶¯ÒÔÓ¢ÎÄ¿Õ¸ñÔÚÆäºóÃæÌî³ä£¬Ê¹³¤¶È´ïµ½ÏàÓ¦µÄ³¤¶È£»¶ø±ä ......