Basic usage of MySQL, water a bit

Source: Internet
Author: User

#和上一篇是一起的, 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.