Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL在查询中隐藏重复地址_Sql_Sql Server_Reporting Services - Fatal编程技术网

SQL在查询中隐藏重复地址

SQL在查询中隐藏重复地址,sql,sql-server,reporting-services,Sql,Sql Server,Reporting Services,我试图在SQLServer2008中创建一个邮件列表,其中显示员工的所有地址,但是,许多员工共享同一地址,我们不希望列表中有重复的地址。我当前的查询不起作用 如何隐藏包含重复地址的行 这是我目前的疑问: SELECT empid, 'empfirstname + emplastname', empaddress, empaddress2, empzipcode, empcity,empstate,empcountry from emp group by empaddress 这就是我

我试图在SQLServer2008中创建一个邮件列表,其中显示员工的所有地址,但是,许多员工共享同一地址,我们不希望列表中有重复的地址。我当前的查询不起作用

如何隐藏包含重复地址的行

这是我目前的疑问:

SELECT
  empid, 'empfirstname + emplastname', 
  empaddress, empaddress2, empzipcode, empcity,empstate,empcountry
from emp
group by empaddress
这就是我目前看到的:

这就是我想要的:


您可以使用窗口分析函数row_number,该函数适用于大多数数据库管理系统,因为我们还不知道您的函数row_number

select *
from
(
select
  name, address, country, ID, -- due to the data on the picture
  row_number() over (partition by address order by id) as rn 
from emp
) q
where rn = 1
不存在以下用途:

select
  e.empid, e.empfirstname + e.emplastname, 
  e.empaddress, e.empaddress2, e.empzipcode,
  e.empcity, e.empstate, e.empcountry
from emp e
where not exists (
  select 1 from emp
  where id < e.id and empaddress = e.empaddress and empzipcode = e.empzipcode
)

我想empaddress和empzipcode足以定义一个不同的地址。

请提供示例数据和预期结果。几行数据可以帮助我们更好地了解您的需求。您的DBMS是什么?什么意思是不工作?