简体   繁体   English

根据其他 3 列的值创建一列

[英]Create a column based on values of 3 other columns

I have group and user data that looks like this:我有如下所示的组和用户数据:

在此处输入图像描述

I need to create a column that indicates whether or not the members of one group are from different companies.我需要创建一个列来指示一个组的成员是否来自不同的公司。

So for Group A, I'd need the new column to indicate the group is mixed because it has a member from Company 1 and a member from Company 2.因此,对于 A 组,我需要新列来表明该组是混合的,因为它有来自公司 1 的成员和来自公司 2 的成员。

Group B, is non-mixed group because all members are from Company 1. B 组是非混合组,因为所有成员都来自公司 1。

Is this possible?这可能吗?

(SSMS 2016) (SSMS 2016)

You can do something like the following using Window functions您可以使用Window 函数执行以下操作

select *, 
    Iif(Min(membercompany) over(partition by groupname)
      =Max(membercompany) over(partition by groupname),'Same','Mixed')
from t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM