2021
02-02
02-02
postgresql 实现字符串分割字段转列表查询
在数据查询中,有一张a表存有另一张b表的id并以‘,'隔开如:假设现在要关联查询关于b表的一些信息,怎么办。分割查询:字符串转列表函数:regexp_split_to_table()select*fromregexp_split_to_table((selectproduct_idsfromfee_project_mealwhereid=116199376233182210),',')查询后,字符串就变成了列表,然后你就可以根据这个列表去找b表的相关信息了。select*frompm.productwhereid::textin(select*from...
继续阅读 >
两个不同的表进行查询,需要把结果合并,比如table1的列为id,user_id,type_id,pro_id;table2的列为id,user_id,collect_id;分别如下图所示table1:table2:将两个表的查询结果合并到一起的查询语句为select*,nullascollect_idfromtable1whereuser_id=527unionselectid,user_id,nullastype_id,nullaspro_id,collect_idfromtable2whereuser_id=527;结果为:其实就是把对应的列补充到没有该列的表中,在例...