oracle查询json,创建JSON并编辑复杂的查询(Oracle 11g)

小编典典

我认为您可以使用以下查询替换大多数代码。您可能需要调整IN子句,如果要更改很多客户列表,这会很麻烦。但这会复制您的结果:

SELECT *

FROM (SELECT DECODE(ppc.customer_class_code, 'E', c.description, ppc.customer_class_code) AS IDENTIFIER, tpp.item_code, tpp.price AS ITEM_PRICE, ppc.price

FROM table_price_list tpl

INNER JOIN table_price_product tpp ON tpp.list_header_id = tpl.list_header_id AND tpp.request_id = tpl.request_id

INNER JOIN prices_per_client ppc ON tpp.item_code = ppc.item_code

LEFT JOIN clients c ON ppc.customer_number = c.account_number

WHERE SYSDATE BETWEEN NVL(tpp.start_date_active, SYSDATE) AND NVL(tpp.end_date_active, SYSDATE+1))

PIVOT (AVG(PRICE) FOR IDENTIFIER IN ('A' AS CLASS_A , 'B' AS CLASS_B, 'SUPERMARKET' AS SUPERMARKET, 'WALMART' AS WALMART));

这是一个更新小提琴。

至于JSON输出,如果您使用的是更高版本,它将变得更加容易,因为

你可能感兴趣的:(oracle查询json)