---涂聚文 2017-9-28
SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord
WHERE
VipExamMailProjectId = 1
GROUP BY VipExamMailStaffID,VipExamMailProjectId HAVING COUNT(1)>1
ORDER BY VipExamMailStaffID
GO --192
SELECT * FROM
(SELECT BranchStaffID,BranchStaffCountryID,BranchStaffIs,BranchStaffArea,BranchStaffCode,BranchStaffNO,BranchStaffName,BranchStaffServerNo FROM VipBranchStaff) a
LEFT JOIN (SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord WHERE VipExamMailProjectId = 1
GROUP BY VipExamMailStaffID,VipExamMailProjectId HAVING COUNT(1)>1) b
ON a.BranchStaffID = b.VipExamMailStaffID
WHERE a.BranchStaffCountryID=1
GO --153 香港
SELECT * FROM VipBranchStaff WHERE BranchStaffCountryID=1 AND BranchStaffIs=1
GO --View_VipExamMailRecordProject SELECT a.*,b.VipExamMailProjectId AS 'ExamProjectId',[dbo].getVipExamBranchSimpleName(a.BranchStaffCode) as 'BranchAreaName',[dbo].getAreaName(a.BranchStaffArea) as 'AreaName',dbo.getVipExamBrandServiceName(dbo.getVipExamBrandServiceNo(a.BranchStaffCode)) AS 'ServerName',
dbo.getVipExamBrandServiceNo(a.BranchStaffCode) AS 'BrandService',[dbo].getVipExamQuestionsIs (b.VipExamMailProjectId,a.BranchStaffID) as 'IsSucces',dbo.getStaffProjectTimes(b.VipExamMailProjectId,a.BranchStaffID) AS 'ExamTimes',dbo.getVipExamMailDate(b.VipExamMailProjectId,a.BranchStaffID) AS 'VipExamMailDate'
FROM
(SELECT BranchStaffID,BranchStaffCountryID,BranchStaffIs,BranchStaffArea,BranchStaffCode,BranchStaffNO,BranchStaffName,BranchStaffServerNo FROM VipBranchStaff WHERE BranchStaffCountryID=1 AND BranchStaffIs=1) a
LEFT JOIN (SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord WHERE VipExamMailProjectId = 1
GROUP BY VipExamMailStaffID,VipExamMailProjectId HAVING COUNT(1)>1) b
ON a.BranchStaffID = b.VipExamMailStaffID
--WHERE a.BranchStaffCountryID=1
GO --国内
--2425
SELECT * FROM VipBranchStaff WHERE BranchStaffCountryID=2 AND BranchStaffIs=1
GO SELECT a.*,b.VipExamMailProjectId AS 'ExamProjectId',[dbo].getVipExamBranchSimpleName(a.BranchStaffCode) as 'BranchAreaName',[dbo].getAreaName(a.BranchStaffArea) as 'AreaName',dbo.getVipExamBrandServiceName(dbo.getVipExamBrandServiceNo(a.BranchStaffCode)) AS 'ServerName',
dbo.getVipExamBrandServiceNo(a.BranchStaffCode) AS 'BrandService',[dbo].getVipExamQuestionsIs (b.VipExamMailProjectId,a.BranchStaffID) as 'IsSucces',dbo.getStaffProjectTimes(b.VipExamMailProjectId,a.BranchStaffID) AS 'ExamTimes' FROM
(SELECT BranchStaffID,BranchStaffCountryID,BranchStaffIs,BranchStaffArea,BranchStaffCode,BranchStaffNO,BranchStaffName,BranchStaffServerNo FROM VipBranchStaff WHERE BranchStaffCountryID=2 AND BranchStaffIs=1) a
LEFT JOIN (SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord WHERE VipExamMailProjectId =2
GROUP BY VipExamMailStaffID,VipExamMailProjectId HAVING COUNT(1)>1) b
ON a.BranchStaffID = b.VipExamMailStaffID
GO SELECT a.*,b.VipExamMailProjectId AS 'ExamProjectId',[dbo].getVipExamBranchSimpleName(a.BranchStaffCode) as 'BranchAreaName',[dbo].getAreaName(a.BranchStaffArea) as 'AreaName',dbo.getVipExamBrandServiceName(dbo.getVipExamBrandServiceNo(a.BranchStaffCode)) AS 'ServerName',
dbo.getVipExamBrandServiceNo(a.BranchStaffCode) AS 'BrandService',[dbo].getVipExamQuestionsIs (b.VipExamMailProjectId,a.BranchStaffID) as 'IsSucces',dbo.getStaffProjectTimes(b.VipExamMailProjectId,a.BranchStaffID) AS 'ExamTimes',dbo.getVipExamMailDate(b.VipExamMailProjectId,a.BranchStaffID) AS 'VipExamMailDate' FROM
(SELECT BranchStaffID,BranchStaffCountryID,BranchStaffIs,BranchStaffArea,BranchStaffCode,BranchStaffNO,BranchStaffName,BranchStaffServerNo FROM VipBranchStaff WHERE BranchStaffCountryID=2 AND BranchStaffIs=1) a
LEFT JOIN (SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord WHERE VipExamMailProjectId =2
GROUP BY VipExamMailStaffID,VipExamMailProjectId HAVING COUNT(1)>1) b
ON a.BranchStaffID = b.VipExamMailStaffID
WHERE dbo.getVipExamBrandServiceNo(a.BranchStaffCode)='013180'
ORDER BY a.BranchStaffCode
GO --2017-09-27修改 合格详情列表
IF EXISTS (select * from sysobjects where [name] = '[proc_Select_HKQualifiedNoDetails]')
DROP PROCEDURE proc_Select_HKQualifiedNoDetails
GO
CREATE PROCEDURE [dbo].proc_Select_HKQualifiedNoDetails
(
@ProjectID int,
@CountryID int,
@BrandService VARCHAR(50),
@search nvarchar(100)
)
as
declare @sql nvarchar(4000),@where nvarchar(4000)
set @sql='SELECT a.*,b.VipExamMailProjectId AS ''ExamProjectId'',[dbo].getVipExamBranchSimpleName(a.BranchStaffCode) as ''BranchAreaName'',[dbo].getAreaName(a.BranchStaffArea) as ''AreaName'',dbo.getVipExamBrandServiceName(dbo.getVipExamBrandServiceNo(a.BranchStaffCode)) AS ''ServerName'',
dbo.getVipExamBrandServiceNo(a.BranchStaffCode) AS ''BrandService'',[dbo].getVipExamQuestionsIs (b.VipExamMailProjectId,a.BranchStaffID) as ''IsSucces'',dbo.getStaffProjectTimes(b.VipExamMailProjectId,a.BranchStaffID) AS ''ExamTimes'',dbo.getVipExamMailDate(b.VipExamMailProjectId,a.BranchStaffID) AS ''VipExamMailDate'' FROM
(SELECT BranchStaffID,BranchStaffCountryID,BranchStaffIs,BranchStaffArea,BranchStaffCode,BranchStaffNO,BranchStaffName,BranchStaffServerNo FROM VipBranchStaff WHERE BranchStaffIs=1 and BranchStaffCountryID='+ cast(@CountryID as varchar)+') a'
+' LEFT JOIN (SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord WHERE VipExamMailProjectId ='+ cast(@ProjectID as varchar)+' GROUP BY VipExamMailStaffID,VipExamMailProjectId HAVING COUNT(1)>1) b ON a.BranchStaffID = b.VipExamMailStaffID'
set @where=''
IF @BrandService<>'' AND @Search=''
SET @where=@where+' where dbo.getVipExamBrandServiceNo(a.BranchStaffCode) like ''%'+@BrandService +'%'''
if @Search<>'' AND @BrandService=''
begin
set @where=@where+' where (a.BranchStaffCode like ''%'+@search +'%'' or [dbo].getVipExamBranchSimpleName(a.BranchStaffCode) like ''%'+@search +'%'' or [dbo].getAreaName(a.BranchStaffArea) like ''%'+@search +'%'' or dbo.getVipExamBrandServiceName(dbo.getVipExamBrandServiceNo(a.BranchStaffCode)) like ''%'+@search +'%'' or [dbo].getVipExamQuestionsIs (b.VipExamMailProjectId,a.BranchStaffID) like ''%'+@search +'%'' or dbo.getVipExamBrandServiceNo(a.BranchStaffCode) like ''%'+@search +'%'')'
END
IF @BrandService<>'' AND @Search<>''
BEGIN
SET @where=@where+' where dbo.getVipExamBrandServiceNo(a.BranchStaffCode) like ''%'+@BrandService +'%'''
set @where=@where+' and (a.BranchStaffCode like ''%'+@search +'%'' or [dbo].getVipExamBranchSimpleName(a.BranchStaffCode) like ''%'+@search +'%'' or [dbo].getAreaName(a.BranchStaffArea) like ''%'+@search +'%'' or dbo.getVipExamBrandServiceName(dbo.getVipExamBrandServiceNo(a.BranchStaffCode)) like ''%'+@search +'%'' or [dbo].getVipExamQuestionsIs (b.VipExamMailProjectId,a.BranchStaffID) like ''%'+@search +'%'' or dbo.getVipExamBrandServiceNo(a.BranchStaffCode) like ''%'+@search +'%'')'
END
set @sql=@sql+@where+' order by ExamTimes'
print @sql
exec(@sql)
GO EXEC proc_Select_HKQualifiedNoDetails 1,1,'',''
GO

  

sql server: left join 重复数据的更多相关文章

  1. SQL Server中删除重复数据

    delete from A ) )

  2. 恢复SQL Server被误删除的数据(再扩展)

    恢复SQL Server被误删除的数据(再扩展) 大家对本人之前的文章<恢复SQL Server被误删除的数据> 反应非常热烈,但是文章里的存储过程不能实现对备份出来的日志备份里所删数据的 ...

  3. 恢复SQL Server被误删除的数据

    恢复SQL Server被误删除的数据 <恢复SQL Server被误删除的数据(再扩展)> 地址:http://www.cnblogs.com/lyhabc/p/4620764.html ...

  4. SQL SERVER 和ACCESS的数据导入导出

            //批量导入Access         string filepath = Server.MapPath("student.mdb");         stri ...

  5. Sql Server 存储过程中查询数据无法使用 Union(All)

    原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...

  6. SQL Server的JOIN是支持使用小括号修改执行顺序的

    假如现在我们的SQL Server数据库中有三个表:[T_A].[T_B]和[T_C],它们的建表语句如下: --建表语句[T_A] CREATE TABLE [dbo].[T_A]( [ID_A] ...

  7. Sql server left join,right join和inner join的比较

    转载于:http://www.2cto.com/database/201206/137067.html   Sql server left join,right join和inner join的比较 ...

  8. SQL Server中Table字典数据的查询SQL示例代码

    SQL Server中Table字典数据的查询SQL示例代码 前言 在数据库系统原理与设计(第3版)教科书中这样写道: 数据库包含4类数据: 1.用户数据 2.元数据 3.索引 4.应用元数据 其中, ...

  9. .SQL Server中 image类型数据的比较

    原文:.SQL Server中 image类型数据的比较 在SQL Server中如果你对text.ntext或者image数据类型的数据进行比较.将会提示:不能比较或排序 text.ntext 和 ...

随机推荐

  1. 连接SSH服务器的脚本,自动发送用户名和密码

    利用expect 自动输入用户名和密码 脚本如下 #!/usr/bin/expect # connect ssh server set timeout 30 spawn ssh -l user_nam ...

  2. Internetworking

    1 Introduction 所谓的InternetWorking就是将很多网络连接起来,那么在这种连接的网络下我们该如何传送封包呢? 2 IP and Routers 1 IP Datagram H ...

  3. Hadoop 综合揭秘——HBase的原理与应用

    前言 现今互联网科技发展日新月异,大数据.云计算.人工智能等技术已经成为前瞻性产品,海量数据和超高并发让传统的 Web2.0 网站有点力不从心,暴露了很多难以克服的问题.为此,Google.Amazo ...

  4. 《机器学习实战(基于scikit-learn和TensorFlow)》第四章内容的学习心得

    本章主要讲训练模型的方法. 线性回归模型 闭式方程:直接计算最适合训练集的模型参数 梯度下降:逐渐调整模型参数直到训练集上的成本函数调至最低,最终趋同与第一种方法计算出的参数 首先,给出线性回归模型的 ...

  5. Facebook的一些基本操作(网页版)

    前期准备 1,注册一次Facebook账号,新建一个应用取到应用id 2,引进Facebook的SDK到页面中: 在js中引进以下代码,初始化 // facebook window.fbAsyncIn ...

  6. asp.net core的docker实践

    如果centos中没有安装和docker和.net core镜像,先安装docker和asp.net core 镜像 安装dockeryum -y install docker-io 启动 Docke ...

  7. Spring Boot+redis存储session,满足集群部署、分布式系统的session共享

    本文讲述spring-boot工程中使用spring-session机制进行安全认证,并且通过redis存储session,满足集群部署.分布式系统的session共享. 原文链接:https://w ...

  8. Apache Commons Beanutils 三 (BeanUtils、ConvertUtils、CollectionUtils...)

    前言 前面已经学习了Apache Commons Beanutils包里的PropertyUtils和动态bean,接下来将学习剩下的几个工具类,个人觉得还是非常实用的,特别是CollectionUt ...

  9. 使用commit方式构建具有sshd服务的centos镜像

    一般我们是通过SSH服务来管理服务器的,但是现在很多Docker镜像不带SSH服务,那我们该如何来管理这些容器呢?现在我们通常使用attach和nsenter工具.但是都无法解决远程管理容器的问题,当 ...

  10. (转)eclipse上传项目到码云

    把Eclipse项目上传到码云的步骤: 1.登录码云:新建项目 2.输入项目名: 3.空项目创建成功如下图: 4.右键点击Eclipse的项目,选择“Team”—————->“Share Pro ...