我有以下查询:
SELECT s."Description",
sp.*
FROM "Supplier" as s
OUTER APPLY (
SELECT p."Id", p."Description", p."Price"
FROM "Products" as p
WHERE p."SupplierId" = s."Id"
FOR JSON auto
) as sp
我正在尝试根据OUTER APPLY
的结果构建json数组,但由于存在错误No column name was specified for column 1 of 'sp'.
,我在这里卡住了,我在stackoverflow上发现了类似的问题,但是没有适用于外部的示例。
您能解释一下该查询出了什么问题吗?
答案 0 :(得分:3)
您只需要添加列别名:
SELECT
s."Description",
sp.*
FROM "Supplier" as s
OUTER APPLY (
SELECT p."Id", p."Description", p."Price"
FROM "Products" as p
WHERE p."SupplierId" = s."Id"
FOR JSON auto
) as sp(json)