在某一天'10 -JAN-11'哪个订单的产品数量最多 [英] On a given day ’10-JAN-11’ which order has most number of products placed
本文介绍了在某一天'10 -JAN-11'哪个订单的产品数量最多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第2行的'where o.date_ordered ='2011-01-10''附近使用正确的语法
这是我得到的错误,我没有得到足够的输出
我尝试过:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where o.date_ordered='2011-01-10'' at line 2
this is the error i got and i am not getting sufficient output
What I have tried:
select o.order_id,p.product_id from orders o,products8 p,order_products8 t where o.order_id=t.order_id and p.product_id=t.product_id
where o.date_ordered='2011-01-10';
推荐答案
为什么你有两个WHERE条款?
你应该看一下JOIN,而不是试图从多个表中选择。我不能为你写它 - 我不知道你的表以及它们是如何相互关联的,但是:
Why do you have two WHERE clauses?
And you should probably look at a JOIN instead of trying to select from multiple tables. I can't write it for you - I have no idea of your tables and how they are interrelated, but:
SELECT a.Name, b.Address FROM Users a
JOIN Addresses b ON a.ID = b.User_ID
WHERE a.JoinDate >= '2018-01-01'
假设order_products8
是一个表,在订单
和products8
表之间有多对多的关系,
- 计算产品数量
Assuming thatorder_products8
is a table with many to many relationships betweenorders
andproducts8
tables,
- to get count of products
SELECT op.order_id, COUNT(op.product_id) CountOfProductsInOrder
FROM order_products8 AS op
GROUPBY op.order_id
WHERE op.date_ordered='2011-01-10';
- 按顺序获得最大数量的产品
- to get max number of products in order
SELECT dt.order_id, MAX(CountOfProductsInOrder) TheHigestNumberOfProductsInOrder
FROM (
-- use above query here
) AS dt
GROUPBY dt.order_id;
这篇关于在某一天'10 -JAN-11'哪个订单的产品数量最多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文