在我的表中,对于重复的“行号”,我有不同的“承包商”,如下所示。
LINE NO CONTRACTOR
L-0001 C-1000
L-0001 C-2000
L-0003 C-6000
L-0003 C-8000
L-0003 C-9000
L-0004 C-5000
现在我想查询如下所示的转置值:
LINE NO CONTRACTOR1 CONTRACTOR2 CONTRACTOR3
L-0001 C-1000 C-2000
L-0003 C-6000 C-8000 C-9000
L-0004 C-5000
请帮助我如何进行此查询?
我做了一个查询,对我的表格数据进行排名如下:
SELECT A.[line no], A.contractor, Count(*) AS ranking, "contractor" & [ranking] AS contractor_rank
FROM Table2 AS A INNER JOIN Table2 AS B ON (A.contractor>=B.contractor) AND (A.[line no] = B.[line no])
GROUP BY A.[line no], A.contractor;
然后对顶部查询进行了交叉表查询,如下所示:
TRANSFORM First(Query4.contractor) AS FirstOfcontractor
SELECT Query4.[line no]
FROM Query4
GROUP BY Query4.[line no]
PIVOT Query4.contractor_rank;
现在可行。
我添加
答案 0 :(得分:1)
我做了一个查询,对我的表格数据进行排名如下:
SELECT A.[line no], A.contractor, Count(*) AS ranking, "contractor" & [ranking] AS contractor_rank
FROM Table2 AS A INNER JOIN Table2 AS B ON (A.contractor>=B.contractor) AND (A.[line no] = B.[line no])
GROUP BY A.[line no], A.contractor;
然后对顶部查询进行了交叉表查询,如下所示:
TRANSFORM First(Query4.contractor) AS FirstOfcontractor
SELECT Query4.[line no]
FROM Query4
GROUP BY Query4.[line no]
PIVOT Query4.contractor_rank;
现在可行。