#和上一篇是一起的, the last one is for this insert<Blockquote>/*Study Questions*/Create DatabaseSPJ; UseSpjCreate Tables (SnoChar(4) not NULL, SnameChar(Ten)NULL, Statusint NULL, CityChar(Ten)NULL,Primary Key(Sno)); UseSpjCreate Tablep (pnoChar(4) not NULL, SnameChar(Ten)NULL, ColorChar(4)NULL, Weightint NULL,Primary Key(pno)); UseSpjCreate TableJ (JnoChar(4) not NULL, JnameChar(Ten)NULL, CityChar(Ten)NULL,Primary Key(Jno)); Create TableSPJ (SnoChar(4) not NULL, pnoChar(4) not NULL, JnoChar(4) not NULL, Qtyint NULL,Primary Key(Sno,pno,jno),Foreign Key(SNO)Referencess (Sno),Foreign Key(pno)Referencesp (pno),Foreign Key(Jno)ReferencesJ (Jno)); /*Quick Copy*/Insert intoTable_bSelect * fromtable_a;/*Insert*/Python F:\python\ project Combat \mysql\mysql.py/*2~8 Questions*//*Query the part code of the lightest part*/SelectPno fromPOrder byWeightASCLimit1; /*inquire about the project name of the part supplied by the supplier S1*/SelectJname fromJJoinSpj onJ.jno=Spj.jnowhereSpj.sno='S1'; /*Query the supplier code that provides parts for both engineering J1 and J2*/Select distinctSpj.sno fromSpjwhereSpj.jno= 'J1' orSpj.jno= 'J2'; /*query supplier code for parts supplied for projects in Shanghai*/Select distinctSpj.sno fromSpjJoinJ onSpj.jno=J.jnowhereJ.city= 'Tianjin'; /*Check the supplier code for red parts for projects in Shanghai or Beijing.*/Select distinctSno fromPjoin SPJ onP.pno=Spj.pnojoin J onJ.jno=Spj.jnowhere P.color='Red' andJ.city='Tianjin' orJ.city='Beijing'; /*find the part code that the supplier and the same supplier in the city of the project can provide*/Select distinctPno fromSjoin SPJ onS.sno=Spj.snojoin J onJ.jno=Spj.jnowhere s.city=j.city;/*Check the Shanghai supplier does not provide any parts of the engineering code Tianjin*/Select distinctJno fromSjoin SPJ onS.sno=Spj.snojoin P onP.pno=Spj.pnowhere s.city<>'Tianjin';</Blockquote># distinctGo heavy
Basic usage of MySQL, water a bit