想检查在其他表中设置的标志

问题描述 投票:0回答:1
 select ky as productcode
from invoice
cross join lateral jsonb_object_keys(contents) as t(ky)
where orgcode=48 and invoice.inoutflag=15
group by ky
order by count(*) desc
limit(5);

现在我得到前五个产品代码,但在其他表名中有一个标志为“product”,如果flag = 7,我想要前五个产品代码。

这是产品表

 productcode | gscode | gsflag | productdesc |  
----------------+----------+----------+------- ----------+

     50      | 444   |   7  |   car     |
sql postgresql
1个回答
0
投票

这是你想要的吗?

select t.ky as productcode
from invoice i cross join lateral
     jsonb_object_keys(i.contents) as t(ky) join
     product p
     on p.productcode = t.ky
where i.orgcode = 48 and i.inoutflag = 15 and
      p.gsflag = 7
group by t.ky
order by count(*) desc
limit 5;
© www.soinside.com 2019 - 2024. All rights reserved.