【数据库】兴唐第二十六节课作业

一、设计购物车表、支付信息表和订单表

思路:
购物车中有:
商品名、价格、生产日期、 保质期(shelf life)、生产厂家。
支付信息中有:
商品名、 价格、 件数、 总价
订单信息有:
发货时间、订单号、预计到货时间、送货地址
代码实现:

create table trolley(
	id int(11) not null auto_increment,
	name varchar(20) not null, 	
	price int(3) not null,
	init_data date not null,
	shelf_life int(1),
	manufacture varchar(20) not null,
	primary key(id)
);

create table payinf(
	id int(11) not null auto_increment primary key,
	name varchar(20) not null,
	price int(3) not null,
	number int(3) not null,
	sum_price int(3) 
);


create table order_form(
	id int(11) not null auto_increment primary key,
	delivery_time date not null,
	arrival_time date not null,
	address varchar(20) not null,
	buyer_name varchar(20) not null	
);

二、已知:【student表】
id name age class_id
101 张三 22 201201
102 李四 20 201203
103 王五 18
105 薛六 19 201202

【class表】
id cnt
201201 2
201202 1
201203 1
201204 2

(1)写出sql语句获取下列查询结果
101 张三 2
102 李四 1
105 薛六 1
(2)写出sql语句获取下列结果
101 张三 2
102 李四 1
103 王五
105 薛六 1

答案:
(1)

select u.id, u.name, a.cnt from student u, class a  where u.class_id = a.id1 order by id;

(2)
使用左连接即可

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值