Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 为投资者划分交易阶段_Sql_Sql Server - Fatal编程技术网

Sql 为投资者划分交易阶段

Sql 为投资者划分交易阶段,sql,sql-server,Sql,Sql Server,我有一个表,其中有一系列连续的投资,然后是对投资作出贡献的投资者。同一项投资不可能有两名投资者,但只有一名投资者投资的第一笔交易是“新的”,未来的每笔交易都列为“非新的” 我现在有两个专栏——Investment&Investor,需要找出编写第三个专栏的SQL,第三个专栏是圆形的 下面列出了示例输出 INVESTMENT | INVESTOR | ROUND | <-- THIRD COLUMN DOESN"T EXIST CURRENTLY ---------------

我有一个表,其中有一系列连续的投资,然后是对投资作出贡献的投资者。同一项投资不可能有两名投资者,但只有一名投资者投资的第一笔交易是“新的”,未来的每笔交易都列为“非新的”

我现在有两个专栏——Investment&Investor,需要找出编写第三个专栏的SQL,第三个专栏是圆形的

下面列出了示例输出

INVESTMENT | INVESTOR |  ROUND  | <-- THIRD COLUMN DOESN"T EXIST CURRENTLY
---------------------------------
|    1     |    A     |  NEW    |
|    2     |    B     |  NEW    |
|    3     |    A     | NOT NEW |
|    4     |    C     |  NEW    |
|    5     |    D     |  NEW    |
|    6     |    B     | NOT NEW |
|    7     |    C     | NOT NEW |
|    8     |    A     | NOT NEW |
|    9     |    E     |  NEW    | 
|   10     |    A     | NOT NEW |
---------------------------------

INVESTMENT | INVESTOR | ROUND |我想你想要
row_number()

select t.*,
       (case when row_number() over (partition by investor order by investment) = 1
             then 'NEW' else 'NOT NEW'
        end) as round
from t;