供應表的簡單查詢

2021-09-02 08:59:02 字數 1120 閱讀 6046

--插入資料

insert into s values ('s1','海南公司','海口');

insert into s values ('s2','雲南公司','昆明');

insert into s values ('s3','杭州公司','杭州');

insert into s values ('s4','北京公司','北京');

insert into p values ('p1','綠茶','1');

insert into p values ('p2','綠茶','2');

insert into p values ('p3','普洱茶','1');

insert into p values ('p4','花茶','1');

insert into p values ('p5','紅茶','1');

insert into sp values ('s1','p1',100); 

insert into sp values ('s2','p3',200);

insert into sp values ('s2','p5',100);

insert into sp values ('s3','p1',400);

insert into sp values ('s3','p2',500);

insert into sp values ('s4','p4',200);

--求**產品編號為p1的**商編號

select sno from sp where pno='p1';

--求**綠茶等級為1的**商編號

select pno from p where pname='綠茶' and kind =1;

select sno from sp  where pno='p1';

--求沒有使用北京公司**商的茶葉,但產品級別是1級茶葉的產品編號

select sno from s where sname='北京公司';

select pno from sp where sno<>'s4';

select pno from p where (pno='p1' or pno='p2' or pno='p3' or pno='p5') and kind=1;

MySQL 查詢表結構簡單命令

一 簡單描述表結構,字段型別 desc tabl name 顯示表結構,字段型別,主鍵,是否為空等屬性,但不顯示外來鍵。例如 desc table name 二 查詢表中列的注釋資訊 select from information schema.columns where table schema ...

簡單的查詢

查詢語法 簡單查詢 select 欄位名1,欄位名2,欄位名3 from 表名 查詢這張表中含有這些欄位的所有資訊 select stuid,stuname,gender,age from studentinfo select from 表名 號代表所有字段 我們不推薦使用 我要什麼資訊就查詢什麼字...

簡單的查詢

查詢全部的行和列。select from 表名 查詢部分的行和列。select 列名 1,列名 2,from 表名 where 條件。在查詢中使用列名的別名。使用as 字句來改變結果中列的名種。select user as 使用者名稱 from 表名 使用 來改變結果中列的名種。select use...