SELECT y.tableid,
c.tableshowname,
y.fieldid,--
y.fieldshowname,--
y.fieldname,
y.fielddatatype,
z.fieldvalue,
cast(z.valueid as text),
string_agg(z.dicname,',')
FROM cp_config_tableinfoadd c,cp_config_tableinfo y
LEFT JOIN
(SELECT a.valueid,
b.fieldid,
c.tableid,
c.tableshowname,
b.fieldshowname,
b.fielddatatype,
a.fieldvalue,
di.dicname
FROM cp_attach_subinfostore a,cp_config_tableinfo b,cp_config_tableinfoadd c,cp_dic_info di
WHERE b.dicid=di.dictypeid and a.fieldid IN
(SELECT fieldid
FROM cp_config_tableinfo
WHERE tableid =302 and isused=1 and isinstalled=0)
AND b.fieldid = a.fieldid
AND b.tableid = c.tableid
AND a.objid=1368 ORDER BY a.subinfoid) z
ON y.fieldid=z.fieldid
WHERE y.tableid=302 and c.tableid=y.tableid and y.isinstalled=0 group by y.fieldid,c.tableshowname,z.fieldvalue,z.valueid order by z.valueid,y.orderintable ;
我是通过分组,多行合并为一列string_agg(z.dicname,','),
现在查出来的结果如下图
后边三列值查不出来了,只有进行分组的那一行有值
1 个解决方案
#1
不做 group by ,把数据弄出来看看,从语句上盾,select 里面有两个列没有在group by 里面
#1
不做 group by ,把数据弄出来看看,从语句上盾,select 里面有两个列没有在group by 里面