我有一个正常工作的sql语句,并产生正确的结果。
SELECT "StoreId", LISTAGG("ProductCategory"
|| ':'
|| '('
|| ProductIds
|| ')', ', ') WITHIN GROUP (
ORDER BY "ProductCategory") AS ProductsAndCategories
FROM
(SELECT "StoreId",
"ProductCategory",
LISTAGG("ProductId", ',') WITHIN GROUP (
ORDER BY "ProductId") AS ProductIds
FROM SUPERMARKET
GROUP BY "StoreId",
"ProductCategory"
) s
GROUP BY "StoreId";
但是,如果我使用完全相同的语句并将其放在View中,我得到的编译器错误并没有多大意义(见下文)。有人告诉我这是有效的,因为使用LISTAGG和视图没有任何限制,但它显然是错误的。我不确定我的陈述有什么问题。有人能指出我吗?
答案 0 :(得分:2)
您的问题似乎与GUI有关。
您可以使用以下方式创建视图:
create view v_storeproducts as
SELECT "StoreId",
LISTAGG("ProductCategory"
|| ':'
|| '('
|| ProductIds
|| '
)', ', ') WITHIN GROUP (ORDER BY "ProductCategory") AS ProductsAndCategories
FROM (SELECT "StoreId",
"ProductCategory",
LISTAGG("ProductId", ',') WITHIN GROUP (ORDER BY "ProductId") AS ProductIds
FROM SUPERMARKET
GROUP BY "StoreId",
"ProductCategory"
) s
GROUP BY "StoreId";