我有这个查询,
(SELECT
[NAME],
[NAME] AS RESULT,
' - ' AS VALUE,
0 AS ORDERING
FROM
[PARTY_MSTR]
UNION ALL
(SELECT
[PARTY_MSTR].[NAME],
' - ' || [T1].[T_NAME],
(SELECT [T2].[T_NAME],
SUM(COALESCE([T2].[VALUE1], 0)) + FROM [T2]
CROSS JOIN [T1] ON [T1].[T_NAME] = [T2].[T_NAME]
GROUP BY [T2].[T_NAME]),
1
FROM
[PARTY_MSTR]
CROSS JOIN [T1]
) AS X;
当我运行此查询时,我收到此错误SELECTs to the left and right of UNION ALL do not have the same number of result columns
现在我删除了评论,第二个错误来自only a single result allowed for a SELECT that is part of an expression
。这个查询出了什么问题。我正在使用SQLite数据库。
答案 0 :(得分:0)
根据评论,联盟左边有四个字段,右边有五个字段。
联合右侧的子选择返回多行。这就是你得到第二个错误的原因。
...请编辑你的代码,以便那里只有SQL。
答案 1 :(得分:0)
解决了它。
(SELECT
[NAME],
[NAME] AS RESULT,
' - ' AS VALUE,
0 AS ORDERING
FROM
[PARTY_MSTR]
UNION ALL
SELECT
[PARTY_MSTR].[NAME],
' - ' || [T1].[T_NAME],
(SELECT VALUE FROM ((SELECT [T2].[T_NAME],
SUM(COALESCE([T2].[VALUE1], 0)) AS VALUE FROM [T2]
CROSS JOIN [T1] ON [T1].[T_NAME] = [T2].[T_NAME]
GROUP BY [T2].[T_NAME]) AS Y)),
1
FROM
[PARTY_MSTR]
CROSS JOIN [T1]
) AS X;