我想从表BAUSER获取每个SELECT a.*, b.* FROM table_a a, table_b b;
的{{1}}(用户的名字)。然而,从我的查询返回结果只显示表中第一个的USER_FNM
- 超级管理员。我不知道出了什么问题 - USER_KEY
是否在子查询中迭代?
这是查询:
USER_FNM
结果如下:
答案 0 :(得分:2)
在子查询中使用PIVOT_LOCATIONS.USER_KEY:
SELECT DISTINCT USER_KEY, (SELECT TOP(1) USER_FNM FROM BAUSER WHERE BAUSER.USER_KEY = PIVOT_LOCATIONS.USER_KEY), SUM([110000003]),SUM([120000002]),SUM([120000003])
FROM CAUSDE_TAS CA
PIVOT
(
SUM(USDE_HSU)
FOR DEPA_KEY IN ([110000003],[120000002],[120000003]
) PIVOT_LOCATIONS
WHERE USDE_DAT >= '01.12.2016' AND USDE_DAT <= '03.02.2017'
AND USER_KEY IN (100000002,100000004,100000006,100000008,100000011)
GROUP BY USER_KEY