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
)
您是否試圖查詢它?你必須有記錄之間的某種聯繫,否則它是不可能的..也嘗試提供一些示例數據和一個關於如何平板電腦附加的圖表,而不是在文本..這清除了很多 –
添加一些解釋 –