db

mysql aggregate function with group by

sunny___ 2022. 4. 27. 10:09
반응형
  • count(), count(distinct)
  • group_concat()
  • json_arrayagg() -> json array aggregate
  • json_objectagg() -> json object aggregate
  • sum(), max(), min()

 

select 
device_type, region
,group_concat(ric_code,'-', country_code) 
,JSON_ARRAYAGG(JSON_OBJECT('cntry',country_code, 'ric',ric_code))
,JSON_OBJECTAGG('cntry',country_code)
from tb_rc_ha_region group by device_type, region

반응형