SQLǶÌ××Ó²éѯ
ʹÓÃ×Ó²éѯµÄÔÔò
1.Ò»¸ö×Ó²éѯ±ØÐë·ÅÔÚÔ²À¨ºÅÖС£
2.½«×Ó²éѯ·ÅÔڱȽÏÌõ¼þµÄÓÒ±ßÒÔÔö¼Ó¿É¶ÁÐÔ¡£
×Ó²éѯ²»°üº¬ ORDER BY ×Ӿ䡣¶ÔÒ»¸ö SELECT Óï¾äÖ»ÄÜÓÃÒ»¸ö ORDER BY ×Ó¾ä,
²¢ÇÒÈç¹ûÖ¸¶¨ÁËËü¾Í±ØÐë·ÅÔÚÖ÷ SELECT Óï¾äµÄ×îºó¡£
ORDER BY ×Ó¾ä¿ÉÒÔʹÓÃ,²¢ÇÒÔÚ½øÐÐ Top-N ·ÖÎöʱÊDZØÐëµÄ¡£
3.ÔÚ×Ó²éѯÖпÉÒÔʹÓÃÁ½ÖֱȽÏÌõ¼þ£ºµ¥ÐÐÔËËã·ûºÍ¶àÐÐÔËËã·û¡£
×Ó²éѯµÄÀàÐÍ
µ¥ÐÐ×Ó²éѯ£º´ÓÄÚ SELECT Óï¾äÖ»·µ»ØÒ»ÐеIJéѯ
¶àÐÐ×Ó²éѯ£º´ÓÄÚ SELECT Óï¾ä·µ»Ø¶àÐеIJéѯ
µ¥ÐÐ×Ó²éѯ
µ¥ÐÐ×Ó²éѯÊÇ´ÓÄÚ²éѯ·µ»ØÒ»ÐеIJéѯ¡£ÔÚ¸Ã×Ó²éѯÀàÐÍÖÐÓÃÒ»¸öµ¥ÐвÙ×÷·û¡£»ÃµÆƬÖÐÁгöÁ˵¥ÐвÙ×÷·û¡£
Àý
ÏÔʾÄÇЩ job ID Óë¹ÍÔ± 141 ÏàͬµÄ¹ÍÔ±¡£
SELECT last_name, job_id
from employees
WHERE job_id =
(SELECT job_id
from employees
WHERE employee_id = 141);
SELECT last_name, job_id, salary
from employees
WHERE job_id =
(SELECT job_id
from employees
WHERE employee_id = 141)
AND salary >
(SELECT salary
from employees
WHERE employee_id = 143);
ÏÔʾ job ID Óë¹ÍÔ± 141 Ïàͬ,²¢ÇÒнˮ ¸ßÓÚ¹ÍÔ± 143 µÄÄÇЩ¹ÍÔ±¡£
×
Ïà¹ØÎĵµ£º
c06 --------------7545623Ìõ
c05---------------1032652Ìõ
vc01--------------427741Ìõ
SQL Statement from editor:
select c0602 "ÉÌÆ·±àÂë",c0625 "ÉÌÆ·ÌõÂë",
c0103 "ÉÌÆ·Ãû³Æ",c0104 "¹æ¸ñ",c060 ......
http://www.javaeye.com/topic/366991#
×÷Ϊһ¸ö¿ª·¢ÈËÔ±£¬¿ªÊ¼ÈÏÕæϵͳѧϰ
Oracle SQLÒ²Ö»ÓÐÔÂÓ֮࣬ǰµÄ
SQLÖª
ʶ½ö½öÊÇÏîÄ¿ÀïÃæÓõ½Ê²Ã´¾ÍÈ¥¿´Ê²Ã´£¬¼òµ¥Ëµ¾ÍÊÇ
Read The Fxxking Guide¡£ÔÚϵͳѧϰ
Oracle
SQL֮ǰ£¬°³µÄÏë·¨¾ÍÊÇ“°´ÕÕÐèÇóÍê³É¹¦ÄÜ£¬Ê£ÏµĽ»¸ø
DBAÀ´´¦À픡£Õâ¸öÏë·¨´ÓÕûÌåÀ´¿´ÏÔ ......
SQL´æ´¢¹ý³Ì·ÖÒ³Ëã·¨Ñо¿(Ö§³ÖǧÍò¼¶)
1.“¶íÂÞ˹´æ´¢¹ý³Ì”µÄ¸ÄÁ¼°æ
CREATE procedure pagination1
(@pagesize int, --Ò³Ãæ´óС£¬Èçÿҳ´æ´¢20Ìõ¼Ç¼
@pageindex int --µ±Ç°Ò³Âë)
as set nocount on
begin
declare @indextable table(id int identity(1,1),nid int) --¶¨Òå±í±äÁ¿
declare @PageL ......
×î½ü¼¸ÖÜÒ»Ö±ÔÚ½øÐÐÊý¾Ý¿âÅàѵ£¬ÀÏʦ¾«Õ¿µÄ¼¼ÊõºÍÉú¶¯µÄ½²½âʹÎÒÊÜÒæ·Ëdz¡£ÎªÁËÈøü¶àµÄÐÂÊÖÊÜÒ棬ÎÒ³é¿Õ°ÑSQLÓï¾äÓÅ»¯²¿·Ö½øÐÐÁËÕûÀí£¬Ï£Íû´ó¼ÒÒ»Æð½ø²½¡£¡¡¡¡
¡¡¡¡Ò»¡¢²Ù×÷·ûÓÅ»¯¡¡¡¡
¡¡1¡¢IN ²Ù×÷·û ¡¡¡¡
¡¡¡¡ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊÇ±È½Ï ......
ÔÚSQL ServerÖÐʹÓÃNewID()·½·¨²úÉúËæ»ú¼¯
ÀýÈ翼ÊÔϵͳÖеÄËæ»ú³öÌâ
¸Õ¿ªÊ¼Ïëµ½µÄÊÇRandomÀà
µ«ÊÇRandomЧÂÊÓеãµÍ
ºóÀ´Ïëµ½ÁËÔÚÊý¾Ý¿âÀïµÄnewid()
ÓÚÊDzÉÓÃÁËϱ߷½·¨£º
select top 5 * from tablename order by newid()
Ôڴ˱ê¼ÇһϠ......