在组SSRS中显示不同的行

时间:2018-10-14 12:29:45

标签: sql-server reporting-services group-by ssrs-2008 distinct

这是复制记录的查询

CREATE TABLE test(
    id int,
    name varchar(20),
    nameID int
);

insert into test
values(1,'test1',1),
      (1,'test2',2),
      (1,'test3',3),
      (1,'test4',4),
      (1,'test5',5)

select 
    t1.name,
    t2.name
from 
    (select * from test where nameID in (1,2)) t1 left join 
    (select * from test where nameID in (3,4,5)) t2 on t1 .id = t2.id

当前输出为

test1 test3
test1 test4
test1 test5
test2 test3
test2 test4
test2 test5

但是我想在SSRS中显示的是

test1 test3
test4
test2 test5

基本上,在每个id组中,我只想显示不同的值。 (背后的逻辑是一个id组(一个文档)可以有多个批准者和soignee) 到目前为止,我一直没有运气尝试HideDuplicatesgroup

1 个答案:

答案 0 :(得分:0)

你在这里

CREATE TABLE test(
    id int,
    name varchar(20),
    nameID int
);

insert into test
values(1,'test1',1),
      (1,'test2',2),
      (1,'test3',3);

SELECT T2.Name, T1.Name
FROM Test T1 LEFT JOIN
     (SELECT * FROM Test WHERE NameID IN (1, 3)) T2 
ON T1.NameID = T2.NameID;

SELECT T1.Name, T2.Name
FROM Test T1 LEFT JOIN
     (SELECT * FROM Test WHERE NameID % 2 = 1) T2 
ON T1.NameID = T2.NameID;

结果:

+-------+-------+
| Name  | Name  |
+-------+-------+
| test1 | test1 |
| test2 |       |
| test3 | test3 |
+-------+-------+