首页 > 解决方案 > SQL:字段的交替值

问题描述

所以,我试图让一件有趣的事情发生,但一直没能真正让它发挥作用。

所以,我的查询:

SELECT a.lead_id
,a.status
,a.[user]
, a.list_id
, a.last_local_call_time
, a.owner
  FROM [LEADS].[dbo].[LDS_VICIDIAL_LIST] a
  inner join leads.dbo.LDS_CONTACT_STATUS b on a.[status]=b.[status]
  where list_id in ('2557','2562','2559') and Dialable='Y' and a.status<>'5NI' and a.called_since_last_reset = 'n'
  order by a.last_local_call_time

基本上我想做的是让它显示列表 2557 中的 1 条记录、列表 2562 中的 1 条记录和 2559 中的 1 条记录并如此重复。

标签: sqlsql-server

解决方案


SELECT a.lead_id
,a.status
,a.[user]
, a.list_id
, a.last_local_call_time
, a.owner
  FROM [LEADS].[dbo].[LDS_VICIDIAL_LIST] a
  inner join leads.dbo.LDS_CONTACT_STATUS b on a.[status]=b.[status]
  where list_id in ('2557','2562','2559') and Dialable='Y' and a.status<>'5NI' and a.called_since_last_reset = 'n'
  order by ROW_NUMBER() OVER (PARTITION BY a.list_id  order by a.list_id) 

得到了我想要的。


推荐阅读