mySQL查询错误'组函数的无效使用'

发布于 2024-11-14 10:40:33 字数 442 浏览 8 评论 0原文

我设置了一个价格比较工具,可以抓取网站,然后检测价格变化。我有一个表,其中包含价格、商品 ID 和扫描 ID。我有另一个表,其中包含项目信息,另一个表包含扫描列表及其发生时间。

我正在尝试进行一个可以检测新产品和价格变化的查询。这就是我所拥有的...但它会导致错误“组函数的使用无效”

SELECT * FROM 
(SELECT * FROM price WHERE scan_id = MAX(scan_id) - 1) as P 

LEFT JOIN 

(SELECT * FROM price WHERE scan_id = MAX(scan_id)) as N 

ON 
P.item_id = N.item_id 
AND P.price != N.price 

JOIN item I ON N.item_id = I.item_id

由于某种原因此查询不起作用。

I have set up a price comparison tool that crawls websites and then detects price changes. I have a table that contains the price, the items id and the scan id. I have another table which contains the item info and another table which contains a list of scans and when they took place.

I am trying to make a query that can detect new products and price changes. This is what I have... but it causes an error 'Invalid use of group function'

SELECT * FROM 
(SELECT * FROM price WHERE scan_id = MAX(scan_id) - 1) as P 

LEFT JOIN 

(SELECT * FROM price WHERE scan_id = MAX(scan_id)) as N 

ON 
P.item_id = N.item_id 
AND P.price != N.price 

JOIN item I ON N.item_id = I.item_id

For some reason this query is not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

污味仙女 2024-11-21 10:40:33

问题出在子查询的 MAX() 部分。我把它取下来,用数字代替,效果很好。

The problem was with the MAX() part of the sub query. I removed it and replaced it with the numbers and it worked a treat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文