数量和最小日期的组项目
我有一个这样的表:
我的目的是创建一个表,该表显示每个订单NUM和ITEM:
- 总量:订购
- 最低预期交货日期
- 总数
的 :
我尝试使用
SELECT 'Order num.',
Item,
SUM(table.Qty) AS 'Total qty',
Supplier,
SUM(table.Qty) * UnitValue AS 'Total price',
MIN(ExpectedDeliveryDate),
MIN(ConfirmedDeliveryDate)
FROM table
GROUP BY 'Order num.', Item, Supplier,
MIN(ExpectedDeliveryDate), MIN(ConfirmedDeliveryDate)
ORDER BY 'Order num.', Item
,但它不起作用。你能帮助我吗?非常感谢。
I've got a table like this:
My intent is to create a table which shows, for each Order num and Item:
- The Total quantity ordered
- The minimum Expected delivery date
- The minimum Confirmed Delivery Date
Like this:
I tried to use
SELECT 'Order num.',
Item,
SUM(table.Qty) AS 'Total qty',
Supplier,
SUM(table.Qty) * UnitValue AS 'Total price',
MIN(ExpectedDeliveryDate),
MIN(ConfirmedDeliveryDate)
FROM table
GROUP BY 'Order num.', Item, Supplier,
MIN(ExpectedDeliveryDate), MIN(ConfirmedDeliveryDate)
ORDER BY 'Order num.', Item
But it doesn't work. Can you help me? Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个问题:您是否真的有一个
订单num
在其中空间?我认为这是不可能的,至少我从未为数据库列名称使用过这样的名称。我进行了一个查询,假设该列被命名为“ ordernum”。同样,对于
订购日期
。通常,在“选择”子句中,您必须使用汇总函数(min,max,...)对于所有不属于“组”的列的列。这意味着除
ordernum
和项目
我不确定所需的“总价格”列,但这意味着所有列,但这应该或多或少产生结果:
A question: Do you really have a column
Order num
with as space in it? I do not think this is possible, at least I never used such a name for a database column name.I made a query that assumes the column is named "Ordernum". Likewise for the
Order date
.In general, in the SELECT clause you have to use aggregate functions (MIN, MAX, ...) for all those columns that are not part of the "GROUP BY". That means for all columns except
Ordernum
andItem
I am not sure about the desired "Total price" column, but this should more or less produce the result: