1.left join 后面加 判断语句 和 where 加 判断语句有什么区别
left join 后加where 约束整个查询结果;
left join 后加and,and条件不能限制左表,仅能限制右表。
例如 from a left join b on a.id=b.id and a.id<5; 此and后条件无效;
例如 form a left join b on a.id=b.id and b.id<5; 可以限制查询结果中b的id小于5;
例如 from a left join b on a.id=b.id where a.id<5; 此where条件可以成功约束查询结果中a的id小于5;
2.为查询出来的语句添加行号
ROW_NUMBER()OVER(ORDER BY ID DESC) AS rank,
3.pgsql 字符串转json数组
①将整张表 转为json数组
array_to_json( array_agg (row_to_json(表名))) AS JsonArray
②将某个字段转为 json数组
array_to_json ( array_agg(( 字段名))) AS JsonArray
③将字段分组后合并
string_agg
4.pgsql 分割
split_part(字段名,'根据什么分割',下标)
例子:split_part ( plan.businessunit, '-', 1 ) AS area
5.pgsql 替换
replace(字段名,'要替换得值','要替换成得值')
replace(string_agg ( file_template, ',' ),'],[',',')