实验2.1
1. 查询商品名称为“挡风玻璃”的商品信息。
select * from autoparts where ap_name='挡风玻璃';
2. 查询ID为1的订单
select * from shopping_order where oid=1
实验2.2
select * from autoparts where is_sale=1 and price<1000;
实验2.3汽车商城
1. 查询所有对商品ID为1的商品发表过评论的用户ID。
select distinct(comment.client_cid) as 用户ID from comment
left join autoparts on comment.autoparts_apid = autoparts.ap_id;
2. 查询此汽车用品网上商城会员的创建时间段,1年为一段。
select c_id,year(create_time) from client group by year(create_time), c_id;
实验2.4
1.查询类别ID为1的所有商品,结果按照商品ID降序排列。
select * from autoparts where second_class_scid=1 order by ap_id desc
2.Ss
select * from client group by year(now()),c_name order by c_name;
实验2.5
1. 查询每个用户的消费总金额(所有订单)。
select client_cid 用户ID, SUM(total_price) 总价 from shopping_order group by client_cid;
2. 查询类别价格一样的各种商品数量总和。
select a.ap_name 商品名称,sum(oha.number) 商品数量 from  autoparts a
left join order_has_autoparts oha on a.ap_id = oha.autoparts_apid
left join shopping_order so der_oid = so.oid
where 1=1
group by oha.autoparts_apid,a.second_class_scid,a.price
实验2.6
1. 查询类别的数量。
select count(category_name) from category
2. 查询汽车用品网上商城的每天的接单数。
select order_date 日期,count(oid) 订单数 from shopping_order where order_status = 1 group by day(order_date),oid;
实验2.7
select order_date 日期,sum(total_price) 每次订单总价 from shopping_order where order_status = 1 group by day(order_date),total_price;
实验2.8
select order_date 日期,avg(total_price) 每次订单总价 from shopping_order where order_status = 1 group by day(order_date),total_price;
实验2.9
select max(hot_product) from autoparts
实验2.10
select min(price) from autoparts
实验2.11
1.查询所有订单的发出者名字。
select distinct(client.c_name) from client
inner join shopping_order on shopping_order.client_cid = client.c_id
2.查询每个用户购物车中的商品名称。
select autoparts.ap_name from autoparts
inner join shopping_cart on autoparts.ap_id = shopping_cart.autoparts_apid
where client_cid = 1