--goods1商品1基本表
create table goods1
(
gkno char(8) primary key, --商品种类编号(主键)
gname varchar(50) not null, --商品名称
gfactory varchar(50) not null, --出厂商
gprice numeric(7,2) not null, --零售价
gmemberprice numeric(7,2) , --会员价
gquantity smallint not null --数量
)--goods2商品2基本表
create table goods2
(
gno char(8) primary key, --商品编号(主键)
gkno char(8) not null foreign key (gkno) references goods1(gkno), --商品种类编号(外键)
gpdate datetime not null, --生产日期
guarantee datetime not null --保质期
)--Sale 购买基本表
create table sale
(
cno char(8) not null, --流水号(外键)
cmemberno char(8) foreign key (cmemberno)references customer(cmemberno), --会员编号(外键)
gno char(8) not null foreign key (gno) references goods2(gno), --商品编号(外键)
price numeric(7,2), --实际价格
sdate datetime not null, --购买日期
sno char(6) not null foreign key (sno) references staff(sno), --员工编号(外键)
primary key(cno,gno) --主键(流水号,商品编号)
)sale表中的记录的cmemberno(会员编号)不为空,那么price为goods1中对应的gmemberprice(会员价),如果cmemberno(会员编号)
为空,则price为goods1中对应的gprice(零售价),要实现这个功能,应该怎么写丫?涉及到多张表,goods1.gno=goods2.gno and
sale.gkno=goods1.gkno
请给位帮忙,我弄了好久了~~~
create table goods1
(
gkno char(8) primary key, --商品种类编号(主键)
gname varchar(50) not null, --商品名称
gfactory varchar(50) not null, --出厂商
gprice numeric(7,2) not null, --零售价
gmemberprice numeric(7,2) , --会员价
gquantity smallint not null --数量
)--goods2商品2基本表
create table goods2
(
gno char(8) primary key, --商品编号(主键)
gkno char(8) not null foreign key (gkno) references goods1(gkno), --商品种类编号(外键)
gpdate datetime not null, --生产日期
guarantee datetime not null --保质期
)--Sale 购买基本表
create table sale
(
cno char(8) not null, --流水号(外键)
cmemberno char(8) foreign key (cmemberno)references customer(cmemberno), --会员编号(外键)
gno char(8) not null foreign key (gno) references goods2(gno), --商品编号(外键)
price numeric(7,2), --实际价格
sdate datetime not null, --购买日期
sno char(6) not null foreign key (sno) references staff(sno), --员工编号(外键)
primary key(cno,gno) --主键(流水号,商品编号)
)sale表中的记录的cmemberno(会员编号)不为空,那么price为goods1中对应的gmemberprice(会员价),如果cmemberno(会员编号)
为空,则price为goods1中对应的gprice(零售价),要实现这个功能,应该怎么写丫?涉及到多张表,goods1.gno=goods2.gno and
sale.gkno=goods1.gkno
请给位帮忙,我弄了好久了~~~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货