{"id":587,"date":"2010-08-24T13:41:00","date_gmt":"2010-08-24T05:41:00","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=587"},"modified":"2023-11-04T13:44:16","modified_gmt":"2023-11-04T05:44:16","slug":"%e9%97%9c%e8%81%af%e5%bc%8f%e4%bb%a3%e6%95%b8","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/587","title":{"rendered":"\u95dc\u806f\u5f0f\u4ee3\u6578"},"content":{"rendered":"\n<p><strong>Relational Algebra(\u95dc\u806f\u5f0f\u4ee3\u6578)<\/strong><br>\u4f9d\u6027\u8cea\u5206\u70ba\u4ee5\u4e0b<br>Unary Relational Operation(\u4e00\u5143\u95dc\u806f\u64cd\u4f5c):\u5c0d\u55ae\u4e00\u95dc\u806f\u64cd\u4f5c<br>Binary Relational Operation(\u4e8c\u5143\u95dc\u806f\u64cd\u4f5c):\u5c0d\u5169\u500b\u95dc\u806f\u64cd\u4f5c,\u4e3b\u8981\u5728\u65bcjoin(\u5408\u4f75)<br>Set Theory Operation(\u96c6\u5408\u8ad6\u64cd\u4f5c):\u4ee5\u96c6\u5408\u8ad6\u70ba\u57fa\u790e<br>Aggregate Function(\u805a\u5408\u51fd\u6578)\u8a08\u7b97<\/p>\n\n\n\n<p><strong>Set Theory Operation<\/strong><br>\u5305\u62ec<br>Intersection Operation(\u4ea4\u96c6\u64cd\u4f5c\uff09<br>Union Operation(\u806f\u96c6\u64cd\u4f5c)<br>Difference Operation(\u5dee\u96c6\u64cd\u4f5c)<\/p>\n\n\n\n<p><strong>Aggregate Functions<\/strong><br>\u805a\u5408\u51fd\u6578\u5305\u62ec<br>\u8a08\u7b97\u52a0\u7e3d\u7684Sum()\u51fd\u6578<br>\u8a08\u7b97\u5e73\u5747\u7684Average()\u51fd\u6578<br>\u8a08\u7b97\u7b46\u6578\u7684Count()\u51fd\u6578<br>\u6700\u5927\u503c\u7684Max()\u51fd\u6578<br>\u6700\u5c0f\u503c\u7684Min()\u51fd\u6578<br>\u8868\u793a\u6cd5\u70ba:&lt; \u7fa4\u7d44\u5c6c\u6027&gt; F&lt; \u51fd\u6578\u8868\u5217&gt;(column operation)(R)<br>ex:<br>&lt; \u8a02\u55ae\u7de8\u865f&gt; F sum(\u5be6\u969b\u55ae\u50f9\u00d7\u6578\u91cf)(\u8a02\u55ae\u660e\u7d30)<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>Unary Relational Operation<\/strong><br>\u5305\u62ec<br><strong>SELECT operation(\u9078\u53d6\u64cd\u4f5c)<\/strong><br>\u3000\u5f9etable\u4e2d\u9078\u53d6col=value\u7684\u8cc7\u6599<br>\u3000\u8868\u793a\u6cd5\u70basigma(col=value)(table)<br><strong>PROJECT operation(\u6295\u5f71\u64cd\u4f5c)<\/strong><br>\u3000\u53ea\u986f\u793atable\u4e2dcol1[,col2,&#8230;]\u6b04\u4f4d\u7684\u8cc7\u6599<br>\u3000\u8868\u793a\u6cd5\u70bapi(col1[,col2,&#8230;])(table)<br><strong>RENAME operation(\u66f4\u540d\u64cd\u4f5c)<\/strong><br>\u3000\u8868\u793a\u6cd5\u70ba\u66ab\u5b58\u95dc\u806f(new col name1[,new col name2,&#8230;])=SELECT or PROJECT operation<\/p>\n\n\n\n<p><strong>\u66ab\u5b58\u95dc\u806f<\/strong><br>\u66ab\u6642\u5132\u5b58\u67d0\u4e9b\u64cd\u4f5c\u5f8c\u6240\u7522\u751f\u7684\u95dc\u806f<br>\u76ee\u7684:\u5c07\u4e00\u9023\u4e32\u7684\u64cd\u4f5c\u5206\u70ba\u6578\u500b\u7368\u7acb\u7684\u64cd\u4f5c\u5206\u5225\u9032\u884c<br>ex1:<br>\u7b2c\u4e00\u7a2e<br>1\u5148\u7be9\u9078\u8cc7\u6599<br>\u7537\u6027\u54e1\u5de5 = sigma(\u6027\u5225=\u2018\u7537&#8217;)(\u54e1\u5de5)<br>2\u5728\u7be9\u9078\u6b04\u4f4d<br>pi(\u54e1\u5de5\u7de8\u865f,\u59d3\u540d,\u8077\u7a31,\u6027\u5225,\u5730\u5740)(\u7537\u6027\u54e1\u5de5)<br>ex2:<br>\u7b2c\u4e8c\u7a2e<br>1\u5148\u7be9\u9078\u6b04\u4f4d<br>\u66ab\u5b58\u54e1\u5de5= pi(\u54e1\u5de5\u7de8\u865f,\u59d3\u540d,\u8077\u7a31,\u6027\u5225,\u5730\u5740)(\u54e1\u5de5)<br>2\u5728\u7be9\u9078\u8cc7\u6599<br>sigma(\u6027\u5225=\u2018\u7537&#8217;)(\u66ab\u5b58\u54e1\u5de5)<\/p>\n\n\n\n<p><strong>\u5c07\u4e00\u9023\u4e32\u7684\u64cd\u4f5c\u6574\u5408\u6210\u55ae\u4e00\u64cd\u4f5c\u9032\u884c<\/strong><br>ex1:<br>\u5148\u6295\u5f71\u64cd\u4f5c,\u5f8c\u9078\u53d6\u64cd\u4f5c<br>sigma(col=value)(<br>pi(col1[,col2,&#8230;])(table1)<br>)<br>ex2:<br>\u5148\u6295\u5f71\u64cd\u4f5c,\u5f8c\u9078\u53d6\u64cd\u4f5c<br>pi(col1[,col2,&#8230;])(<br>sigma(col=value)(table2)<br>)<br>ps<br>\u6ce8\u610f\u4e8b\u9805,\u4e0d\u53ef\u4ea4\u63db\u7684\u60c5\u5f62<br>ex:<br>\u6295\u5f71\u64cd\u4f5c\u6642\u7121\u6027\u5225\u7684\u6b04\u4f4d,\u56e0\u6b64\u5728\u9078\u53d6\u64cd\u4f5c\u7121\u6cd5\u4f9d\u6027\u5225\u505a\u904e\u6ffe<br>sigma(\u6027\u5225=\u2018\u7537&#8217;)(<br>pi(\u54e1\u5de5\u7de8\u865f,\u59d3\u540d,\u8077\u7a31,\u5730\u5740)(\u54e1\u5de5)<br>)<\/p>\n\n\n\n<p><strong>ex1<\/strong><br><strong>\u5217\u51fa\u54e1\u5de5sex(\u6027\u5225)\u70baM,salary(\u85aa\u6c34)&gt;32000\u7684\u54e1\u5de5\u59d3\u540d(EMPLOYEE.fname,EMPLOYEE.lname)<\/strong><br>pi(fname,lname)(<br>sigma(sex=M &amp;&amp; salary&gt;32000)(employee)<br>)<br>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p><strong>Binary Relational Operation<\/strong><br>\u5305\u62ec<br><strong>CROSS JOIN<\/strong><br>\u3000\u8868\u793a\u6cd5\u70baR X S<br><strong>THETA JOIN<\/strong><br>\u3000\u8868\u793a\u6cd5\u70baR X(\u689d\u4ef6\u60c5\u5f62) S<br>\u3000\u5305\u542b==,&lt; ,&gt;,!=,=&gt;,=&lt;<br><strong>EQUIJOIN JOIN&nbsp;<\/strong>\u5c6c\u65bcTHETA JOIN\u7684\u5b50\u96c6\u5408<br>\u3000\u53ea\u5305\u542b==, \u76f8\u540c\u5c6c\u6027\u4ecd\u7136\u6703\u5728\u51fa\u73fe,\u4e5f\u5c31\u662f\u6703\u67092\u6b04\u4f4d\u540d\u7a31\u4e00\u6a23<br>\u3000\u8868\u793a\u6cd5\u70baR |X| (\u689d\u4ef6\u60c5\u5f62)S<br>\u3000ex: (R) |X|(R.a=S.b)(S) \u7559\u4e0bR.a\u548cS.b<br><strong>NATURE JOIN<\/strong><br>\u3000\u53ea\u5305\u542b==,\u76f8\u540c\u5c6c\u6027\u53ea\u6703\u51fa\u73fe\u4e00\u6b21,\u4e5f\u5c31\u662f\u53ea\u7559\u4e0b\u4e00\u6b04\u4f4d<br>\u3000\u8868\u793a\u6cd5\u70baR * (\u689d\u4ef6\u60c5\u5f62)S = R |X|(r.a=s.b)S<br>\u3000ex: (R) *(R.a=S.b)(S) \u53ea\u7559\u4e0bR.a<br><strong>OUTER JOIN<\/strong><br>\u3000\u8868\u793a\u6cd5\u5206\u70ba<br>\u3000left outer join R ]x| (\u689d\u4ef6\u60c5\u5f62)S<br>\u3000right outer join R |x[ (\u689d\u4ef6\u60c5\u5f62)S<br>\u3000full outer join R ]x[ (\u689d\u4ef6\u60c5\u5f62)S<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><br><strong>ex1<br>\u627e\u51fajohn smith\u7684\u89aa\u5c6c(depedent_name,relationship)<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>depandent(essn,depandent_name,sex,bdate,relationship)<br>1<br>\u627e\u51faemployee\u70bajohn smith\u7684\u8cc7\u6599<br>emp_john=pi(fname,lname,ssn) (<br>sigma(fname=john &amp;&amp; lname=smith)(employee)<br>)<br>2<br>john\u89aa\u5c6c\u689d\u4ef6emp.ssn=depadent.ssn<br>pi(depedent_name,relationship)(<br>(employee) |X|(emp_john.ssn=depadent.essn)(depandent)<br>)<strong><br>ex2<br>\u5217\u51fa\u6bcf\u500b\u90e8\u9580\u7684\u7d93\u7406\u59d3\u540d(DEPARTMENT.dname,EMPLOYEE.fname,EMPLOYEE.lname)<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>department(dname,dnumber,mgr_ssn,mgr_start_date)<br>1<br>pi(dname,fname,lname)(<br>(department) |X|(department.mgr_ssn=employee.ssn)(employee)<br>)<strong><br>ex3<br>\u5217\u51fa\u5c08\u6848productx\u76ee\u524d\u6709\u90a3\u4e9b\u54e1\u5de5\u5728\u8ca0\u8cac(employee.fname,employee.lname)<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>project(pname,pnumber,plocation,dnum)<br>works_on(essn,pro,hours)<br>1<br>ptab=pi(pname,pnumber)(<br>sigma(pname=projectx)(project)<br>)<br>2<br>pwtab=pi(essn)(<br>(ptab)|X|(pnumber=pro)(works_on)<br>)<br>3<br>result=pi(fname,lname)(<br>(pwtab)|X|(essn=ssn)(employee)<br>)<strong><br>ex4<br>\u5217\u51fa\u6bcf\u500b\u5c08\u6848\u76ee\u524d\u6709\u54ea\u4e9b\u54e1\u5de5\u8ca0\u8cac(PROJECT.pname,EMPLOYEE.fname,EMPLOYEE.lname)<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>project(pname,pnumber,plocation,dnum)<br>works_on(essn,pro,hours)<br>\u65b9\u6cd5a<br>1<br>pwtab=pi(essn,pname)(<br>(project)|X|(pnumber=pno)(works_on)<br>)<br>2<br>result=pi(PWTAB.pname,EMPLOOYEE.fname,EMPLOYEE.lname)(<br>(pwtab)|X|(essn=ssn)(employee)<br>)<br>\u65b9\u6cd5b<br>R1=((project)|X|pnumber=pno(works_on))|X|essn=ssn(employee)<br>result=pi(pname,fname,lname)(R1)<br>\u65b9\u6cd5c<br>result=pi(PROJECT.pname,EMPLOOYEE.fname,EMPLOYEE.lname)(<br>\u3000(employee)|X|(ssn=essn)(<br>\u3000\u3000(project)|X|(pnumber=pno)(works_on)\u3000\u3000<br>\u3000\u3000)<br>\u3000)<strong><br>ex5<br>\u5217\u51fa\u8ca0\u8cac\u5c08\u6848\u6240\u5728\u5730\u70bahouston\u7684\u54e1\u5de5,\u4f46\u90e8\u9580\u4e0d\u5728houston(fname,lname,address)<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>project(pname,pnumber,plocation,dnum)<br>works_on(essn,pro,hours)<br>dept_locations(dnumber,dlocation)<br>1<br>R1=(((project)|X|pnumber=pno(works_on))|X|essn=ssn(employee))|X|dno=dnumber(dept_locations)<br>2<br>result=pi(fname,lname,address)(<br>segma(dlocation=houston &amp;&amp; plocation=houston)(R1)<br>)<\/p>\n\n\n\n<p>ps:<br>\u905e\u8ff4\u5c01\u9589\u5f0f\u64cd\u4f5c<br>\u54e1\u5de5 = pi(\u54e1\u5de5\u7de8\u865f, \u59d3\u540d, \u5831\u544a\u4eba)(\u54e1\u5de5)<br>\u4e0a\u53f8 = pi(\u54e1\u5de5\u7de8\u865f, \u59d3\u540d, \u8077\u7a31, \u5831\u544a\u4eba)(\u54e1\u5de5)<br>tmp_result = (\u54e1\u5de5)|X| \u54e1\u5de5.\u5831\u544a\u4eba=\u4e0a\u53f8.\u54e1\u5de5\u7de8\u865f &amp;&amp; \u8077\u7a31=&#8217;\u696d\u52d9\u7d93\u7406'(\u4e0a\u53f8)<br>result = pi(\u54e1\u5de5.\u54e1\u5de5\u7de8\u865f, \u54e1\u5de5.\u59d3\u540d, \u4e0a\u53f8.\u54e1\u5de5\u7de8\u865f, \u4e0a\u53f8.\u59d3\u540d)(tmp_result )<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p><strong>\u96c6\u5408\u9664\u6cd5<\/strong><br>R \/ S<br>\u5217\u51faS\u5728R\u4e2d\u540c\u6642\u51fa\u73fe\u7684\u8cc7\u6599<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>R(a ,b)<br>a1 b1<br>a1 b2<br>a2 b1<br>a2 b3<br>a3 b1<br>a3 b2<br>a3 b3<\/td><td>S(b)<br>b1<br>b2<\/td><td>R\/S<br>S\u4e2db\u7684b1,b2\u5728R\u4e2da1,a3\u8cc7\u6599\u4e2d<br>(a)<br>a1<br>a3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><br><strong>ex1<br>\u5217\u51fa\u540c\u6642\u5728\u6bcf\u500b\u5c08\u6848\u4e2d\u5de5\u4f5c\u7684\u54e1\u5de5(EMPLOYEE.fname,EMPLOYEE.lname)<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>project(pname,pnumber,plocation,dnum)<br>works_on(essn,pro,hours)<br>1<br>R(pno)=pi(pnumber)(project)<br>2<br>\u5728works_on\u4e2d\u53d6\u5f97\u64c1\u6709\u5168\u90e8R.pno(=WORKS_ON.pno)\u7684essn<br>R1=(work_on)\/(R)<br>3<br>result=pi(fname,lname)(<br>(EMPLOYEE)|X|ssn=essn(R1)<br>)<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/p>\n\n\n\n<p><strong>\u96c6\u5408\u6e1b\u6cd5<\/strong><br>R &#8211; S<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>R(ssn)<br>1<br>2<br>3<br>4<br>5<\/td><td>S(ssn,pno)<br>1 a<br>2 a<br>3 a<br>4 a<br>1 b<br>2 b<br>3 b<br>1 c<br>3 c&nbsp;<\/td><td>R-S<br>R\u4e2d\u76845\u6c92\u6709\u51fa\u73fe\u5728S\u7684ssn\u8cc7\u6599\u4e2d<br>(ssn)<br>5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>ex1<br>\u5217\u51fa\u6c92\u6709\u5c08\u6848\u7684\u54e1\u5de5<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>project(pname,pnumber,plocation,dnum)<br>works_on(essn,pro,hours)<br>1<br>R1(ssn)=pi(essn)(works_on)<br>2<br>R2(ssn)=pi(ssn)(employee)<br>3<br>R3=R2-R1<br>4<br>result=pi(fname,lname)(<br>(employee)*(R3)<br>)<strong><br>ex2<br>\u5217\u51fa\u7121\u89aa\u5c6c\u7684\u7d93\u7406<\/strong><br>\u8cc7\u6599\u8868\u5982\u4e0b<br>employee(fname,minit,lname,ssn,bdate,address,sex,salary,super_ssn,dno)<br>depandent(essn,depandent_name,sex,bdate,relationship)<br>1<br>R(ssn)=pi(super_ssn)(employee)<br>2<br>S(ssn)=pi(essn)(dependent)<br>3<br>T=R-S<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Relational Algebra(\u95dc\u806f\u5f0f\u4ee3\u6578)\u4f9d\u6027\u8cea\u5206\u70ba &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16],"tags":[],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-database"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=587"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/587\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}