SELECT id,firstName,lastName, SUM(qty*price)
FROM orders,menu,customers
WHERE menu.id = orders.id_menu
AND orders.id_customer = customers.id
GROUP BY (id,firstName,lastName)
ORDER BY (SUM(qty*price)) LIMIT 1;
我需要得到最好的客户
答案 0 :(得分:3)
编写SQL时的一些简单规则:
FROM
语法。您生成的查询更有可能第一次运行:
JOIN
答案 1 :(得分:-1)
将查询更改为此
SELECT customers.id,firstName,lastName, SUM(qty*price) FROM orders,menu,customers WHERE menu.id = orders.id_menu AND orders.id_customer = customers.id GROUP BY (customers.id,firstName,lastName) ORDER BY (SUM(qty*price)) LIMIT 1;
我相信所有这些表都有一个名为'id'的列,你需要指定你需要哪一个,否则它会给你这个消息。
答案 2 :(得分:-1)
您有许多列名称' id'在不同的表中,所以mysql无法知道它来自哪里(menu.id vs customer.id)。
答案 3 :(得分:-1)
更改为:
SELECT id,firstName,lastName, SUM(qty*price)
FROM orders,menu,customers
WHERE menu.id = orders.id_menu
AND orders.id_customer = customers.id
GROUP BY (orders.id,firstName,lastName)
ORDER BY (SUM(qty*price)) LIMIT 1;
你想要orders.id,因为那些将与数量和价格相关联