这是复制记录的查询
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)
到目前为止,我一直没有运气尝试HideDuplicates
和group
。
答案 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 |
+-------+-------+