标签:weight order div stat join key insert reference database
#和上一篇是一起的,上一篇就是为这个做insert <blockquote>/*思考题*/ create database spj; use spj;create table s( sno char(4) not null, sname char(10) null, status int null, city char(10) null, primary key(sno) ); use spj;create table p( pno char(4) not null, sname char(10) null, color char(4) null, weight int null, primary key(pno) ); use spj;create table j( jno char(4) not null, jname char(10) null, city char(10) null, primary key(jno) ); create table spj( sno char(4) not null, pno char(4) not null, jno char(4) not null, qty int null, primary key(sno,pno,jno), foreign key(sno) references s(sno), foreign key(pno) references p(pno), foreign key(jno) references j(jno) ); /*快速复制*/insert into table_B select * from table_A; /*插入*/python F:\python\项目实战\mysql\mysql.py /*2~8题*/ /*查询重量最轻的零件的零件代码*/ select pno from p order by weight asc limit 1; /*查询由供应商S1提供零件的工程项目名*/ select jname from j join spj on j.jno=spj.jno where spj.sno=‘s1‘; /*查询同时为工程J1和J2提供零件的供应商代码*/ select distinct spj.sno from spj where spj.jno= ‘j1‘ or spj.jno = ‘j2‘; /*查询为位于上海的工程提供零件的供应商代码*/ select distinct spj.sno from spj join j on spj.jno=j.jno where j.city= ‘天津‘; /*查询同时为位于上海或北京的工程提供红色零件的供应商代码*/ select distinct sno from pjoin spj on p.pno=spj.pnojoin j on j.jno=spj.jnowhere p.color=‘红‘ and j.city=‘天津‘ or j.city=‘北京‘; /*查询供应商和工程所在城市相同的供应商能提供的零件代码*/ select distinct pno from sjoin spj on s.sno=spj.snojoin j on j.jno=spj.jnowhere s.city=j.city; /*查询上海供应商不提供任何零件的工程代码 天津*/ select distinct jno from sjoin spj on s.sno=spj.snojoin p on p.pno=spj.pnowhere s.city<>‘天津‘;</blockquote> # distinct 去重
标签:weight order div stat join key insert reference database
原文地址:https://www.cnblogs.com/euraxluo/p/9145991.html