Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.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标识云ID_Sql_Sql Server - Fatal编程技术网

SQL标识云ID

SQL标识云ID,sql,sql-server,Sql,Sql Server,我正在分析一个数据集。表有3列: -CLOUD_ID (ID Field) example: 121312 -CURRENT_Action (Textfield) example: Started -MIN_STARTDATE (Date) example: 2016-04-20 17:03:58.633 我需要将未删除当前操作的云ID标识为最小最小开始日期。您可以使用窗口功能: select distinct cloud_id from (select t.*,

我正在分析一个数据集。表有3列:

-CLOUD_ID (ID Field) example: 121312

-CURRENT_Action (Textfield) example: Started

-MIN_STARTDATE (Date) example: 2016-04-20 17:03:58.633

我需要将未删除当前操作的云ID标识为最小最小开始日期。

您可以使用窗口功能:

select distinct cloud_id
from (select t.*,
             min(min_startdate) over (partition by cloud_id) as min_min_startdate
      from t
     ) t
where min_startdate = min_min_startdate and
      Current_Action <> 'Deleted';

注意:这假设当前操作不是空的,但可以很容易地包含在逻辑中。

您可以使用窗口函数:

select distinct cloud_id
from (select t.*,
             min(min_startdate) over (partition by cloud_id) as min_min_startdate
      from t
     ) t
where min_startdate = min_min_startdate and
      Current_Action <> 'Deleted';

注:这假设当前动作不为空,但很容易包含在逻辑中。

稍微不同的方法,请比较性能:

with x as (select *, row_number() over(partition by cloud_id order by min_startdate) rn from @t)
select cloud_id from x where rn = 1 and current_action <> 'deleted'

一个稍微不同的方法,请比较性能:

with x as (select *, row_number() over(partition by cloud_id order by min_startdate) rn from @t)
select cloud_id from x where rn = 1 and current_action <> 'deleted'

这行得通吗:从当前动作所在的表中选择*删除“嗨,游戏大战,没有原因我需要与最小日期的关系。”。每个云ID都有几个入口,我需要确定哪些入口没有被删除,因为这是第一个操作。哦,好的。谢谢。添加更多示例数据会有帮助。您是否也可以查看此链接以改进后续问题:这是否有效:选择*从当前操作所在的表中删除?'Deleted'Hi thegameiswar,没有理由我需要最小日期的关系。每个云ID都有几个入口,我需要确定哪些入口没有被删除,因为这是第一个操作。哦,好的。谢谢。添加更多示例数据会有帮助。你可以看看这个链接来改进问题:比我快几秒钟;嗨,戈登·林诺夫,谢谢你的快速回复。这一个工作,给了我预期的结果!谢谢你的帮助。乔看了我几秒钟;嗨,戈登·林诺夫,谢谢你的快速回复。这一个工作,给了我预期的结果!谢谢你的帮助。乔