查询列之间的差异
我有此样品数据:
ID | 颜色 | 气味 |
---|---|---|
1 | 红色 | 臭 |
1 | 黄色 | 花状 |
1 | 绿色 | 中性 |
2 | 蓝色 | 臭 |
2 | 蓝色 | 花状 |
2 | 蓝色 | 花,类似于 |
单个ID的utiple行。
我想要的结果是要有这样的东西:
ID | 备注 |
---|---|
1种 | 不同的颜色,不同的气味 |
2 | 不同的气味 |
相同的行值是ID,如果该列有任何差异(例如,使用ID 2,ID 2,气味像花一样,臭)说“不同的气味”
我还不是专业人士,所以我不知道是否可能。我正在考虑选择不同的ID,何时和加入的情况,但是在进行查询时,我会陷入下一步。
可以做到吗?
I have this sample data:
ID | Color | Scent |
---|---|---|
1 | Red | Stinky |
1 | Yellow | Flower-like |
1 | Green | Neutral |
2 | Blue | Stinky |
2 | Blue | Flower-like |
2 | Blue | Flower-like |
There are mutiple rows pertaining to the single ID.
The result I want is to have something like this:
ID | Remarks |
---|---|
1 | Different colors, different scents |
2 | Different scents |
The same value for the rows is the ID, and if there are any difference in that column (for example, with ID 2, the scents are flower-like and stinky) make a remark "Different scents"
I'm not yet a pro, so I don't know if it's possible. I'm thinking of selecting distinct IDs, case when, and joins, but when doing the query, I'm stuck on what should be the next step.
Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您可以使用
concat_ws
的组合(假设您使用了SQL Server的完全支持版本,否则您不陈述),case
和计数(不同)
:Seems you can use a combination of
CONCAT_WS
(assuming you're on a fully supported version of SQL Server, as you don't state otherwise),CASE
andCOUNT(DISTINCT)
: