检索表中的重复名称(非数字)

时间:2018-08-31 21:45:32

标签: sql sql-server

我将附加一个链接,该链接准确显示了我所面临的问题,并显示了代码和应该发生的情况的描述。

查看链接:https://www.screencast.com/t/Zo3BH0i3v

如果您不想打开该链接,下面我将解释问题:

首先,代码:

--Query Duplicate Document Names--

SELECT count(dcd.Name)'How Many Duplicates', dcf.Name 'Folder Name', dcf.ID 
            'Folder ID', dcd.ID 'Document ID', dcd.name 'Document Name', 
            'https://' + txtcityssldomainname + '/' + 'Admin/DocumentCenter/Folder/Index/' 
            + Cast (FK_FolderID AS VARCHAR) AS Link_To_Folder
FROM tblcitysettings tblcs, DocumentCenterDocuments dcd
JOIN DocumentCenterFolders dcf on dcf.ID = dcd.FK_FolderID
WHERE dcf.FK_Status IN (40,10) AND (dcd.FK_Status IN (40,10)) AND 
      (dcd.IsArchived IN (0)) AND (dcf.Name NOT IN ('Content', 'Design', 'Banners', 
      'MyAccount'))
GROUP BY dcf.Name, dcf.ID, dcd.ID, dcd.Name, 'https://' + txtcityssldomainname
         + '/' + 'Admin/DocumentCenter/Folder/Index/' + Cast (FK_FolderID AS VARCHAR)
HAVING count(dcd.Name) = 1
ORDER BY dcd.ID

应该发生什么,它应该为出现一次的每个文档在“ 1”的第一列中返回一个计数。如果文档出现不止一次,它将连接这些行并显示出现多少的值。

它不起作用,我完全不知所措。

任何帮助将不胜感激!

以下是已编辑的工作副本:

注意:我已经意识到,当存在其他不相同的值时,我试图在列中合并一个奇异值。因此,如何合并这些字符串?我重新编写了代码以显示最低限度的代码。

SELECT count(dcd.DisplayName) 'Number of Duplicate Entries', dcd.DisplayName 'Document Name'

FROM DocumentCenterDocuments dcd

JOIN DocumentCenterFolders dcf on dcf.ID = dcd.FK_FolderID

where dcd.IsArchived IN (0) AND (dcd.FK_Status IN (40, 10)) AND (dcf.FK_Status IN (40, 10)) AND (dcf.Name NOT IN ('Content', 'Design', 'Banners', 'MyAccount'))

GROUP BY dcd.DisplayName

Having count(dcd.DisplayName) > 1 

谢谢!

0 个答案:

没有答案