sql 在sql中选择包含多个数据的Distinct行

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 在sql中选择包含多个数据的Distinct行相关的知识,希望对你有一定的参考价值。

with supp as ( 
Select 
			ROW_NUMBER() over (partition by WVTSupporter.id order by WVTSupporter.id desc ) rn,			
			convert(nvarchar(100),WVTProductHeader.code) ProductCode,			
            WVTSupporter.id SupporterID,			
      From dbo.WVTContribution
                  Inner Join dbo.WVTSupporter                 
						ON WVTContribution.p_mySupporterExtra = WVTSupporter.myExtraInfo      
		WHERE		
		WVTProductHeader.code = '16FAMGRP'
),

supp1 as ( 
Select 
			ROW_NUMBER() over (partition by WVTSupporter.id order by WVTSupporter.id desc ) rn,			
			convert(nvarchar(100),WVTProductHeader.code) ProductCode,			
            WVTSupporter.id SupporterID,			
      From dbo.WVTContribution
                  Inner Join dbo.WVTSupporter                 
						ON WVTContribution.p_mySupporterExtra = WVTSupporter.myExtraInfo      
		WHERE		
		WVTProductHeader.code = '16FAMGRP'
)



SELECT * from supp
INNER JOING supp1 ON supp=supp1
where Rn = 1
with supp as ( 
Select 
			ROW_NUMBER() over (partition by WVTSupporter.id order by WVTSupporter.id desc ) rn,			
			convert(nvarchar(100),WVTProductHeader.code) ProductCode,			
            WVTSupporter.id SupporterID,			
      From dbo.WVTContribution
                  Inner Join dbo.WVTSupporter                 
						ON WVTContribution.p_mySupporterExtra = WVTSupporter.myExtraInfo      
		WHERE		
		WVTProductHeader.code = '16FAMGRP'
)

SELECT * from supp where Rn = 1

以上是关于sql 在sql中选择包含多个数据的Distinct行的主要内容,如果未能解决你的问题,请参考以下文章

SQL语句 包含怎么写

如何从 T-SQL 表中提取最新值

SQL 从多个表中选择列而不重复数据

从 spark 数据框或 sql 中选择具有偏好层次结构的多个记录

如何在JAVA JPA Spring Boot中的一个SQL查询中选择多个数据

oracle sql - 选择具有多个“case when”的语句并检查是不是包含文本