sql语句练习
一、如何查找每个分类中最贵的商品
1、创建数据库,插入数据
creare database jingdong charset=utf8;
use jingdong;
create table goods(
id int unsigned primary key auto_increment not null,
name varchar(150) not null,
cate_name varchar(40) not null,
brand_name varchar(40) not null,
price decimal(10.3) not null default 0,
is_show bit not null default 1,
is_saleoff bit not null default 0);
--插入数据
insert into goods values(0,'r510vc 15.6英寸笔记本','笔记本','华硕','3399',default,default);
2、-- 求所有商品的平均价格,并且保留两位小数
select round(avg(price),2) from goods;
– 查询所有价格大于平均价格的商品,并且按价格降序排序
select name from goods
where price >