MS Access 中的子查询问题
我不太确定为什么以下查询无法在 Access 中运行。 它要求我提供 s1.sku 的值
SELECT s1.SkuApexId, s1.sku, s1.apex, s1.btw, s1.gebruikernr, q2.*
FROM tblSkuApex AS s1,
(SELECT MAX(s2.begindatum)
FROM tblskuapex s2
WHERE s1.sku = s2.sku) q2
I'm not quite sure why the following query won't run in Access.
It asks me to give the value of s1.sku
SELECT s1.SkuApexId, s1.sku, s1.apex, s1.btw, s1.gebruikernr, q2.*
FROM tblSkuApex AS s1,
(SELECT MAX(s2.begindatum)
FROM tblskuapex s2
WHERE s1.sku = s2.sku) q2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照您的说法,您需要与 q2 表进行交叉联接,该交叉联接将根据 s1 表的每个记录的 s1.sku 值而变化,这是不可接受的。
我认为您应该将 q2 子查询放置为列而不是表。由于您检索单个值,因此可以很容易地这样放置:
或者甚至更好,为什么不将其作为普通聚合获取,因为您从同一个表请求最大值:
注意:您可以在任何地方省略 s1 别名
The way you put it, you require a cross join to the q2 table, which is to be changing depending on the s1.sku value of each record of the s1 table, which is unacceptable.
I think you should place the q2 subquery as a column and not as a table. Since you retrieve a single value, it could be easily put like this:
or even better, why dont you get it as a normal aggregation, since you request the max from the same table:
note: you could ommit the s1 alias everywhere