如下图
二、数据如下
-- 查询演练
-- 求所有电脑产品的平均价格,并且保留两位小数
-- SELECT ROUND(AVG(price),2) FROM goods
-- 查询所有价格大于平均价格的商品,并且按价格降序排序
-- SELECT * FROM goods WHERE price>(SELECT ROUND(AVG(price),2) FROM goods)
-- ORDER BY price desc
-- 查询类型为'超极本'的商品价格
-- SELECT price FROM goods WHERE cate='超级本'
-- 查询价格大于或等于"超级本"价格的商品,并且按价格降序排列
-- SELECT * FROM goods WHERE price>=ANY(SELECT price FROM goods WHERE cate='超级本')
-- ORDER BY price DESC
-- = any 或者 =some 等价 in
-- 数据分表
-- 创建“商品分类”表
-- CREATE table goods_cate(
-- cate_id int unsigned primary key auto_increment,
-- cate_name varchar(20)
-- )
-- SELECT DISTINCT cate FROM goods
-- 把商品分类插入到‘商品分类’表
-- 将A表的数据插入到新表(B)数据的方法 如下:INSERT INTO 字段(一个字段)xxx(xxx就是A表区分处理的数据)
-- INSERT INTO goods_cate(cate_name)SELECT DISTINCT cate FROM goods
-- 创建“商品品牌”表 且插入数据 查询出来的字段名,插入到创建表的相同的字段名
-- DROP table if exists goods_brand;
-- create table goods_brand(
-- brand_id int unsigned primary key auto_increment,
-- brand_name VARCHAR(20)
-- )SELECT DISTINCT brand_name FROM goods
-- 备份表
-- create table goods_back SELECT * FROM goods