答案 0 :(得分:2)
Case When ((ROW_NUMBER() OVER( PARTITION BY CltsVcdos ORDER BY CltsVcdos ASC) ) =1) then 1 else 0 end
您可以使用以上条件获得UNIQUEVALUES 以下示例进一步解释
CREATE TABLE [dbo].[TB_PRUEBAS](
[CltsVcdos] [int] NULL
) ON [PRIMARY]
INSERT [dbo].[TB_PRUEBAS] ([CltsVcdos]) VALUES (101)
INSERT [dbo].[TB_PRUEBAS] ([CltsVcdos]) VALUES (101)
INSERT [dbo].[TB_PRUEBAS] ([CltsVcdos]) VALUES (101)
INSERT [dbo].[TB_PRUEBAS] ([CltsVcdos]) VALUES (102)
INSERT [dbo].[TB_PRUEBAS] ([CltsVcdos]) VALUES (102)
INSERT [dbo].[TB_PRUEBAS] ([CltsVcdos]) VALUES (104)
SELECT
ROW_NUMBER() OVER(ORDER BY CltsVcdos ASC) AS Row#,
[CltsVcdos],
(ROW_NUMBER() OVER( PARTITION BY CltsVcdos ORDER BY CltsVcdos ASC) ) As RepeatedRowNumber ,
Case When ((ROW_NUMBER() OVER( PARTITION BY CltsVcdos ORDER BY CltsVcdos ASC) ) =1) then 1 else 0 end As UNIQUEVALUES
FROM [dbo].[TB_PRUEBAS] P
答案 1 :(得分:0)
这假设您有某种identity
列,它指定了排序
select CltsVcdos,
(case when count(CltsVcdos) over (partition by CltsVcdos by <identity_col>) > 1
then 0 else 1 end) as UniquValues
from TB_PRUEBAS