0
映射表我有这些表:如何在没有FK
- 洗车
- 为了
- orderHistory
- 用户
- 服务
连接:一个carWash
许多orders
,一个order
即可一个orderHistory
,一个carWash
许多services
,一个user
许多orders
的问题是:当用户创造秩序,他选择通过car_wash例如提供的一些服务(wash_car_body = $ 20,wash_wheels = $ 10)从服务表和当用户想要查看订单历史时,我想向用户显示所有选择的服务,如何更好地执行此操作?
我的服务脚本:
create table services(
id SERIAL not null,
car_wash_id int not null,
name text not null,
price double precision not null,
car_body text,
CONSTRAINT "gmoika_service_company_id_fKey" FOREIGN KEY (car_wash_id)
REFERENCES car_wash (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
洗车脚本:
create table services(
id SERIAL not null,
name text not null)
例如
insert into services (car_wash_id, price , name car_body) values (1,20,wheels_wash,sedan)
当用户创建以便与id来car_wash = "id"
我用下面的脚本给他所有的服务,
select * from services s where s.car_wash_id = "id".
然后用户选择服务。我想将选择的服务保存到订单历史中。 OrderHistory脚本
CREATE TABLE order_history(
id SERIAL not null,
order_id int,
wash_price double precision,
car_body text,
box_number int,
car_wash_name text,
currency text,
time timestamp with time zone NOT NULL,
status text,
CONSTRAINT "gmoika_wash_history_id_fKey" FOREIGN KEY (order_id)
REFERENCES order (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
您是否试图查询它?你必须有记录之间的某种联系,否则它是不可能的..也尝试提供一些示例数据和一个关于如何平板电脑附加的图表,而不是在文本..这清除了很多 –
添加一些解释 –