Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

´«ÖDz¥¿Í£­Tree in SQL£¨ÒëÎÄ£©£¨3£©

This has some predictable results that we can use for building queries. The root is always of the form (left = 1, right = 2 * (SELECT COUNT(*) from TreeTable)); leaf nodes always have (left + 1 = right); the BETWEEN predicate defines the subtrees; and so on. Here are some common queries that you can use to build others:
ÎÒÃÇ¿ÉÒÔÀûÓÃһЩ¿ÉÔ¤¼ûµÄ½á¹û¹¹½¨²éѯ£¨±í´ïʽ£©¡£¸ù²¿×ÜÊÇÒÔÕâÖÖÐÎʽ¹¹³É£¨left = 1, right = 2 * (SELECT COUNT(*) from TreeTable)£©£»Ò¶×Ó½ÚµãÔò×ÜÊÇ£¨left + 1 = right£©£»BETWEEN±í´ï¶¨ÒåÁË×ÓÊ÷£»µÈµÈ¡£ÕâÀïÓÐһЩ³£ÓõIJéѯ£¬Äã¿ÉÒÔÓÃËüÃÇÀ´×齨¸ü¶àÆäËû£¨²éѯ£©£º
1. Find an employee and all his/her supervisors, no matter how deep the tree.
²éÕÒÒ»¸ö¹ÍÔ±¼°Ëû/ËýµÄËùÓÐÉϼ¶£¬ÎÞÂÛÕâ¿ÅÊ÷½á¹¹ÓжàÉî¡£
SELECT P2.*
from Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P1.emp = :myemployee;
2. Find the employee and all his/her subordinates. (This query has a nice symmetry with the first query.)
²éÕÒ¹ÍÔ±¼°Ëû/ËýËùÓÐÏÂÊô¡££¨Õâ¸ö²éѯÓëµÚÒ»¸ö²éѯÐγÉÁ¼ºÃµÄ¶Ô³Æ¡££©
SELECT P2.*
from Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P2.emp = :myemployee;
3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries that each employee controls:
¸øÕâЩ»ù±¾²éѯÌí¼ÓGROUP BY£¨¹Ø¼ü×Ö£©ºÍ×ܼƺ¯ÊýÕâÑùÄã¾ÍÓзּ¶¼Ç¼ÁË¡£ÀýÈ磬ÿ¸ö¹ÍÔ±ÄÜÖ§ÅäµÄн³ê×ÜÊý£º
SELECT P2.emp, SUM(S1.salary)
from Personnel AS P1, Personnel AS P2,
Salaries AS S1
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P1.emp = S1.emp
GROUP BY P2.emp;
In the adjacency list method, this has to be done with a cursor.
ÔÚÁÚ½ÓÁбíģʽÀ±ØÐëÒÀ¿¿Óα꣨cursor£©²ÅÄÜÕâÑù×ö¡£
4. Find the level of each node, so you can print the tree as an indented listing.
²éÕÒÿ¸ö½ÚµãµÄ¼¶±ð£¬ÕâÑùÄã¾ÍÄܹ»ÒÔËõ½øÁбíÐÎʽ´òÓ¡Õâ¿ÃÊ÷ÁË¡£
SELECT COUNT(P2.emp) AS indentation, P1.emp
from Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
GROUP BY P1.emp
ORDER BY P1.lft;
5. The nested set mod


Ïà¹ØÎĵµ£º

ASP.NETÁ¬½ÓSQLºÍACCESSµÄ·½·¨

SQL:
using System.Data.SqlClient;
string sql = "server=.;uid=sa;pwd=;database=tablename;";
ACCESS:
using System.Data.OleDb;
string sql = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + HttpRuntime.AppDomainAppPath + "//App_Data//db.mdb";
HttpRuntime.AppDomainAppPath Ϊ¸ùĿ¼
......

JSP + SQL server 2000¿ª·¢»·¾³µÄ´î½¨

     ´Ó×òÌ쿪ʼ¾ÍÒ»Ö±ÔÚÍøÉϲéÕÒÊý¾Ý¿âΪSQL server 2000 µÄJSP¿ª·¢»·¾³µÄ´î½¨£¬µ½ÏÖÔÚΪֹÖÕÓÚÄܹ»Õý³£Áª½Ó²¢·ÃÎÊ¡£ÒÔÏÂÊǴµÄ²½Ö裺
1¡¢´ÓÍøÉÏÏÂÔØÒ»¸öSQL server 2000 ¸öÈ˰æµÄ°²×°°ü£¬°´ÕÕÌáʾ²Ù×÷£¬µ±ÔÚÉí·ÖÑé֤ʱ£¬Ñ¡Ôñ»ìºÏģʽ£¬Óû§saµÄÃÜÂë¿ÉÒÔΪ¿Õ£¬Ò²¿ÉÒÔ²»Îª¿Õ¡£
2¡¢´ÓÍøÉÏÏÂÔØÒ»¸öSQ ......

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓ㨶þ£©

¸ÄÉÆSQLÓï¾ä
¡¡¡¡ºÜ¶àÈ˲»ÖªµÀSQLÓï¾äÔÚsql serverÖÐÊÇÈçºÎÖ´Ðеģ¬ËûÃǵ£ÐÄ×Ô¼ºËùдµÄSQLÓï¾ä»á±»SQL SERVERÎó½â¡£±ÈÈ磺
select * from table1 where name=''zhangsan'' and tID > 10000
ºÍÖ´ÐÐ:
select * from table1 where tID > 10000 and name=''zhangsan''
¡¡¡¡Ò»Ð©È˲»ÖªµÀÒÔÉÏÁ½ÌõÓï¾äµÄÖ´ÐÐЧÂÊÊÇ·ñÒ» ......

SQL SERVER Êý¾ÝÀàÐÍÏê½â


Êý¾ÝÀàÐÍ
ÀàÐÍ
Ãè              Êö
bit
ÕûÐÍ
bit Êý¾ÝÀàÐÍÊÇÕûÐÍ£¬ÆäÖµÖ»ÄÜÊÇ0¡¢1»ò¿ÕÖµ¡£ÕâÖÖÊý¾ÝÀàÐÍÓÃÓÚ´æ´¢Ö»ÓÐÁ½ÖÖ¿ÉÄÜÖµµÄÊý¾Ý£¬ÈçYes »òNo¡¢True »òFa lse ¡¢On »òOff
int
ÕûÐÍ
int Êý¾ÝÀàÐÍ¿ÉÒÔ´æ´¢´Ó- 231(-2147483648)µ½231 (2147483 ......

Áù¸ö½¨Òé·ÀÖ¹SQL×¢Èëʽ¹¥»÷

     SQL×¢Èë¹¥»÷µÄΣº¦ÐԺܴó¡£ÔÚ½²½âÆä·ÀÖ¹°ì·¨Ö®Ç°£¬Êý¾Ý¿â¹ÜÀíÔ±ÓбØÒªÏÈÁ˽âÒ»ÏÂÆä¹¥»÷µÄÔ­Àí¡£ÕâÓÐÀûÓÚ¹ÜÀíÔ±²ÉÈ¡ÓÐÕë¶ÔÐԵķÀÖδëÊ©¡£
¡¡  Ò»¡¢ SQL×¢Èë¹¥»÷µÄ¼òµ¥Ê¾Àý¡£
¡¡¡¡statement := "SELECT * from Users WHERE Value= " + a_variable + "
    ÉÏÃæÕâÌõÓï¾äÊÇºÜÆ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ