SQL的执行顺序从前到后依次是:
8.0.29 社区版
本次演示用到两张表,存放商品信息的“product”表与存放商店信息的“shopproduct”表。表内容与代码的来源均来自于日本作家MICK所著的《SQL基础教程》,此处仅为学习分享使用,如有不妥请联系我删除。
product表的表结构与具体内容如下:
product表-表结构
字段名称 | 实际含义 |
---|---|
product_id | 商品编号,具有唯一性 |
product_name | 商品名称 |
product_type | 商品种类 |
sale_price | 商品销售单价 |
purchase_price | 商品进货单价 |
regist_data | 商品信息登记日期 |
shopproduct表的表结构与具体内容如下:
shopproduct表-表结构
字段名称 | 字段含义 |
---|---|
shop_id | 商店编号 |
shop_name | 商店名称 |
product_id | 商品编号 |
quantity | 商店内商品库存数量 |
shopproduct表-具体内容
为了方便小伙伴自己动手理解过程,创建表两张表的代码如下:
#创建product表
CREATE TABLE Product
(product_id CHAR(4) NOT NULL,
product_name VARCHAR(100) NOT NULL,
product_type VARCHAR(32) NOT NULL,
sale_price INTEGER ,
purchase_price INTEGER ,
regist_date DATE ,
PRIMARY KEY (product_id));
#向product表中插入具体记录
INSERT INTO Product VALUES ('0001', 'T恤衫', '衣服', 1000, 500,'2009-09-20');
INSERT INTO Product VALUES ('0002', '打孔器', '办公用品', 500,320, '2009-09-11');
INSERT INTO Product VALUES ('0003', '运动T恤', '衣服', 4000,2800, NULL);
INSERT INTO Product VALUES ('0004', '菜刀', '厨房用具', 3000,2800, '2009-09-20');
INSERT INTO Product VALUES ('0005', '高压锅', '厨房用具', 6800,5000, '2009-01-15');
INSERT INTO Product VALUES ('0006', '叉子', '厨房用具', 500,NULL, '2009-09-20');
INSERT INTO Product VALUES ('0007', '擦菜板', '厨房用具', 880,790, '2008-04-28');
INSERT INTO Product VALUES ('0008', '圆珠笔', '办公用品', 100,NULL, '2009-11-11');
#创建shopproduct表
CREATE TABLE ShopProduct
(shop_id CHAR(4) NOT NULL,
shop_name VARCHAR(200) NOT NULL,
product_id CHAR(4) NOT NULL,
quantity INTEGER NOT NULL,
PRIMARY KEY (shop_id, product_id));
#向shopproduct表中插入具体记录
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000A', '东京', '0001', 30);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000A', '东京', '0002', 50);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000A', '东京', '0003', 15);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000B', '名古屋', '0002', 30);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000B', '名古屋', '0003', 120);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000B', '名古屋', '0004', 20);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000B', '名古屋', '0006', 10);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000B', '名古屋', '0007', 40);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000C', '大阪', '0003', 20);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000C', '大阪', '0004', 50);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000C', '大阪', '0006', 90);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000C', '大阪', '0007', 70);
INSERT INTO ShopProduct (shop_id, shop_name, product_id, quantity) VALUES ('000D', '福冈', '0001', 100);
<< · Back Index ·>>