select
b.tenmh,
(
SELECT madh_hb, mamh, mact, tenmathang, madt, mahomh, slkh, tenct, tennl, cao, rong, dai, sl1bo, tongslton, sl_nhan_scg, sl_nhan_scg, ghichu, (slcan-tongslton) as slcan2 from view_chitietlenhsx2 a where madh_hb='INC_NANTUCKET-CHERRY-VAL_05_17' and (sl_thieunhan_scg + tongslton) <0 and scsx=1 and maloainl='NLTN' AND a.tenmh = b.tenmh for json auto
) AS details
from (select DISTINCT tenmh from view_chitietlenhsx2 where madh_hb='INC_NANTUCKET-CHERRY-VAL_05_17' and (sl_thieunhan_scg + tongslton) <0 and scsx=1 and maloainl='NLTN') b
FOR json auto