Fe_Order_Items
fe_order_items_id
fe_order_specification_id
fe_users_id
fe_menu_items_id
fe_order_items_quantity
fe_order_items_time_order
Fe_Order_Specification
fe_order_specification_id
fe_users_id
fe_users_address_id
fe_users_email_address_id
fe_users_phone_number_id
fe_menu_items_id
fe_menu_items_quantity
fe_payment_customer_payment_order_total
fe_payment_customer_payment_acceptance
fe_payment_customer_payment_acceptance_by_food_express
fe_payment_customer_method_of_payment
fe_customer_service_order_process_start
fe_delivery_system_order_signed_by_customer_before_delivery
fe_delivery_system_order_order_delivered_to_customer
total
我运行的查询(导师帮助了我,因为仍然很难拿出一些东西来计算总数(已订购的所有插入菜单项):
SELECT fe_order_specification.fe_order_specification_id,
fe_menu_items.fe_menu_items_name,
SUM(fe_menu_items.price `fe_menu_items_quantity`) AS Total
FROM fe_order_items
INNER JOIN fe_menu_items ON fe_order_items.fe_menu_items = fe_menu_items.fe_menu_items_id
INNER JOIN fe_order_specification ON fe_order_items.`fe_order_specification` = fe_order_specification.`fe_order_specification_id`
WHERE fe_order_items.fe_order_specification=1
GROUP BY fe_order_items.fe_menu_items
mysql并没有给我带来可观的总和,而是给了我一些法语(和英语((我的设置是在英语UK上,所有内容都是英语)):
1054-“ con_dans”字段列表中的“ fe_order_specification.fe_order_specification_id”冠军
答案 0 :(得分:0)
我希望查询看起来如下:
SELECT SUM(mi.price * oi.quantity)
FROM order_items AS oi
JOIN menu_items AS mi ON mi.id = oi.menu_item_id
WHERE oi.order_id = @ORDERID
但是,恐怕这与您当前的数据模型不匹配...我会更改...
数据模型如下所示(请注意,我删除了对查询不重要的字段):
order_items:
id (PK) (AUTO INCREMENTED) (INT)
order_id (FK) (INT)
menu_item_id (FK) (INT)
quantity (INT)
菜单项:
id (PK) (AUTO INCREMENTED) (INT)
price (DECIMAL)
其他说明:
user_id
存储在order
表中(尚未定义)type (ENUM) ['dinner','dessert']