0
什麼,我要做的是計算diner_payment_due(DINER TABLE
),由food_serve_size(FS_DINER TABLE
)SQL乘2列的2頁不同的表
CREATE TABLE diner (
diner_no NUMBER(8) NOT NULL,
diner_payment_due NUMBER(6,2) NOT NULL,
diner_seat_no NUMBER(2) NOT NULL,
diner_seated DATE NOT NULL,
diner_completed DATE,
table_no NUMBER(2) NOT NULL
);
CREATE TABLE food_serve (
food_item_no NUMBER(4) NOT NULL,
food_serve_size CHAR(2) NOT NULL,
food_serve_kilojoules NUMBER(4) NOT NULL,
food_serve_cost NUMBER(5,2) NOT NULL
);
CREATE TABLE FS_DINER (
DINER_NO NUMBER(8) NOT NULL,
FOOD_ITEM_NO NUMBER(4) NOT NULL,
FOOD_SERVE_SIZE CHAR(2 BYTE) NOT NULL,
FS_DINER_NO_SERVES NUMBER(1) NOT NULL,
FS_DINER_ITEM_SERVED CHAR (1) NOT NULL,
CONSTRAINT pk_fs_diner PRIMARY KEY (DINER_NO, FOOD_ITEM_NO,FOOD_SERVE_SIZE)
);
乘以food_serve_cost(FOOD_SERVE TABLE
)我只需要返回一個值和然後插入餐桌,我想我需要做一個Inner Join
,然後只需sum (food_serve_cost * NO_SERVES)
然後group by DINER_NO
?基於其他兩個表中的值
INSERT INTO DINER (DINER_NO, DINER_PAYMENT_DUE, DINER_SEAT_NO, DINER_SEATED, DINER_COMPLETED, TABLE_NO) INSERT INTO DINER VALUES (1, SELECT SUM (FOOD_SERVE.FOOD_SERVE_COST * FS_DINER..., , 1, 1/05/2017, 1 /05/2017, 1);
什麼口味的SQL這是,什麼你嘗試過這麼遠嗎?你是試圖一次找到所有的條目,還是隻爲特定的條目? –
只是oracle的sql,我只需要返回一個值,然後插入到餐桌,即時通訊想我需要做一個內部連接,然後簡單地sum(food_serve_cost * NO_SERVES),然後由DINER_NO組? INSERT INTO DINER(DINER_NO,DINER_PAYMENT_DUE,DINER_SEAT_NO,DINER_SEATED, DINER_COMPLETED,TABLE_NO) INSERT INTO DINER VALUES(1,SELECT SUM (FOOD_SERVE.FOOD_SERVE_COST * FS_DINER ...,1, 2017年1月5日, 2017年1月5日,1); – adam
請分享樣本數據和期望的結果。 – zarruq