我有一张有上千件拍卖品的table。有些拍卖品会马上卖出,有些则会在随后的拍卖会上以较低的价格重新上市。每个拍卖项目条目在数据库中都有一个唯一的条目id(因此,当项目重新输入时,它将获得一个新的登录id),但也有一个唯一的项目标识符,该标识符不会随着重新登录而更改。
此外,还有拍卖物品的类别,以及特定的品牌和类型(例如,“家具”类别有很多清单,其中制造商“la-z-boy”是一个品牌,然后“躺椅”是一个更具体的类型)。
重新列出的项目将以新的唯一id和新的价格重新输入数据库,但唯一项目标识符保持不变,所有其他列/属性保持不变。我可以找到所有价格发生变化的商品:
SELECT category, unique_item_identifier FROM auction_listings WHERE category='furniture' GROUP BY unique_item_identifier HAVING COUNT(*)>1;
这个查询的问题是,它只返回唯一标识符、类别和计数,但我无法查看价格变化。另外,如果我尝试对查询进行更具体的处理,例如。
SELECT category, brand, unique_item_identifier FROM auction_listings WHERE category='furniture' GROUP BY unique_item_identifier HAVING COUNT(*)>1;
这失败的原因是:“select列表的表达式#2不在group by子句中,并且包含功能上不依赖于group by子句中的列的未聚合列;这与sql\u mode=only\u full\u group by不兼容
我想看看所有的拉z男孩都有价格变化,然后也看看那些价格变化是什么。我还希望能够运行一个查询,显示所有的la-z-boys(无论类型)有价格变化,所以我还希望能够选择category,brand,type where brand='la-z-boy'(然后显示所有的la-z-boys有价格变化,输出包括不同的价格)。
我正在寻找输出,例如:
unique-1 la-z-boy recliner price: $1000 entered on 1/1/2018
unique-1 la-z-boy recliner price: $800 entered on 2/1/2018
unique-2 la-z-boy recliner price: $1,200 entered on 1/1/2018
unique-2 la-z-boy recliner price: $1,050 entered on 2/1/2018
unique-2 la-z-boy recliner price: $950 entered on 3/1/2018
unique-3 la-z-boy couch price: $1,200 entered on 1/1/2018
unique-3 la-z-boy couch price: $1,000 entered on 2/1/2018
提前感谢-我在这里读了几十个答案,都非常接近这个具体的要求,但找不到这个明确,无法从其他答案中找出如何做到这一点。
1条答案
按热度按时间xdnvmnnf1#
您尚未提供示例数据,但希望下面的内容足以说明原理
如果在子查询中,我们识别出那些薪资变动超过1次的人,我们可以返回以获取详细信息
如果要选择特定用户,请在子查询中包含where子句