mySQL查询错误'组函数的无效使用'
我设置了一个价格比较工具,可以抓取网站,然后检测价格变化。我有一个表,其中包含价格、商品 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在子查询的 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.