如何仅选择最大食物订单id?
SELECT
o.food_order_id,
fo.user_id,
f.name,
f.price,
o.quantity,
o.subtotal
FROM food_order fo
INNER JOIN order_item o ON fo.food_order_id = o.food_order_id
INNER JOIN food_item f ON o.food_id = f.food_id
WHERE fo.user_id = 12;
如果我想更新或删除从表中选择的信息,我将如何做?
table:
CREATE TABLE food_item (
food_id SERIAL PRIMARY KEY,
name TEXT,
image TEXT,
description TEXT,
price INT
);
CREATE TABLE food_order (
food_order_id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(user_id)
);
CREATE TABLE order_item (
order_item_id SERIAL PRIMARY KEY,
food_id INT REFERENCES food_item(food_id),
food_order_id INT REFERENCES food_order(food_order_id),
quantity INT,
subtotal INT
);
1条答案
按热度按时间rkkpypqq1#
在postgres 13中,你可以使用
FETCH FIRST WITH TIES
:在旧版本中,我建议: