with tem as(SELECT
extract(yearfrom bucket::date)asyear,
extract(quarter from bucket::date)as quarter ,
extract(monthfrom bucket::date)asmonth,
extract(week from bucket::date)as week,
extract(dayfrom bucket::date)asday,*FROM ludp_pdp
WHERE product_name='DVX'and version='20160118')select
geo,subgeo,country,region,productName,product,siteId,version ,seller,color,mram,mrom,xcvr,
json_agg(json_build_object('quarters',quarters,'value',pdpFinal))as res
from(SELECTyear||'-'||quarter as quarters,
geo,subgeo,country,region,product_name as productName,product,site_id as siteId ,
version,seller,color,mram,mrom,xcvr ,sum(tem.pdp_final)as pdpFinal
FROM tem
GROUPBY
geo,subgeo,country,region,product_name,product,site_id,version ,seller,color,mram,mrom,xcvr,year,quarter
orderbyyear,quarter
) t groupby
geo,subgeo,country,region,productName,product,siteId,version ,seller,color,mram,mrom,xcvr
2. 返回字符串拼接
with tem as(SELECT
extract(yearfrom bucket::date)asyear,
extract(quarter from bucket::date)as quarter ,
extract(monthfrom bucket::date)asmonth,
extract(week from bucket::date)as week,
extract(dayfrom bucket::date)asday,*FROM ludp_pdp
WHERE product_name='DVX'and version='20160118')select
geo,subgeo,country,region,productName,product,siteId,version ,seller,color,mram,mrom,xcvr,
string_agg(res,',') res
from(SELECTyear||'-'||quarter||':'||sum(tem.pdp_final)as res,
geo,subgeo,country,region,product_name as productName,product,site_id as siteId ,
version,seller,color,mram,mrom,xcvr
FROM tem
GROUPBY
geo,subgeo,country,region,product_name,product,site_id,version ,seller,color,mram,mrom,xcvr,year,quarter
orderbyyear,quarter
) t GROUPBY geo,subgeo,country,region,productName,product,siteId,version ,seller,color,mram,mrom,xcvr