数据库:
Transaction ProductID
1 1000
2 1000
2 1001
3 1000
3 1002
4 1000
4 1001
5 1003
在上表中,如何用 T-SQL 语句找到这个结果?
+-------------+-----------+-----------------+
| PRODUCTID1 | PRODUCTID2| SUPPORT |
+-------------+-----------+-----------------+
| 1000 | 1001 | 2 |
+-------------+-----------+-----------------+
| 1000 | 1002 | 1 |
+-------------+-----------+-----------------+
| 1000 | 1003 | 0 |
+-------------+-----------+-----------------+
| 1001 | 1002 | 0 |
+-------------+-----------+-----------------+
| 1001 | 1003 | 0 |
+-------------+-----------+-----------------+
| 1002 | 1003 | 0 |,
+-------------+-----------+-----------------+
测试表:
create table transactions(
ORDERID INT,
PRODUCTID INT
);
insert into transactions(ORDERID, PRODUCTID)
values ('1', '1000')
,('2', '1000')
,('2', '1001')
,('3', '1000')
,('3', '1002')
,('4', '1000')
,('4', '1001'),
('5', '1003');
提前致谢。