postgre基于行数的外连接及python连接postgre数据库
2022/2/23 19:24:19
本文主要是介绍postgre基于行数的外连接及python连接postgre数据库,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
外连接
左外/右外连接
- 左外连接:左表全部出现在结果集中,若右表无对应记录,则相应字段为
NULL
- left join ... on 条件
- 右外连接:右表全部出现在结果集中,若左表无对应记录,则相应字段为
NULL
- right join ... on 条件
全外连接
- 两个表均出现在结果集中,无对应记录的相应字段为
NULL
- full join/full outer join ... on 条件
- pg中基于行数进行全外连接:
- create table join_1 as (select * from(select *, row_number()over() rn from customer) as a full join(select *, row_number()over() rn1 from district) as b on a.rn=b.rn1);
python连接pg数据库
点击查看代码
# 外连接 ## 左外/右外连接 * 左外连接:左表全部出现在结果集中,若右表无对应记录,则相应字段为`NULL` * left join ... on 条件 * 右外连接:右表全部出现在结果集中,若左表无对应记录,则相应字段为`NULL` * right join ... on 条件 ## 全外连接 * 两个表均出现在结果集中,无对应记录的相应字段为`NULL` * full join/full outer join ... on 条件 * pg中基于行数进行全外连接: * create table join_1 as (select * from(select *, row_number()over() rn from customer) as a full join(select *, row_number()over() rn1 from district) as b on a.rn=b.rn1); # python连接pg数据库 import numpy as np import psycopg2 import pandas as pd connect = psycopg2.connect(database='test', user='Sevent', password='', port='5432' ) # 创建一个cursor来执行数据库的操作 cur = connect.cursor() sql = "SELECT 目标列 FROM full_join"df = pd.read_sql(sql, con=connect) # df.dropna(axis=0, how='any', inplace=True) # 删除缺省值,全连接会产生很多缺省 # 转换成array df1 = np.array(df) # 转换成列表 my_list = df1.tolist() print(df) # df
这篇关于postgre基于行数的外连接及python连接postgre数据库的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python