sql的注入问题 连接查询 子查询

配合execute,列表化参数,或者正则匹配

 # 数据库的链接
con = pymysql.connect(host='localhost', user='root', password='mysql', database='waterDB', port=3306,charset='utf8')  
 #操作对象
cur = con.cursor()  
cur.execute()  可以执行数据库语句

连接查询
内连接查询
select * from (customer inner join address) on id=cus_id;
select * from customer inner join address on customer.id=address.cus_id;
左连接查询
select * from customer left join address on customer.id=address.cus_id;
右连接查询
select * from customer as a right join address as b on a.id=b.cus_id;
1.内连接

1.1.等值连接:在连接条件中使用等于号(=)运算符比较被连接列的列值,其查询结果中列出被连接表中的所有列,包括其中的重复列。

1.2.不等值连接:在连接条件使用除等于运算符以外的其它比较运算符比较被连接的列的列值。这些运算符包括>、>=、<=、<、!>、!<和<>。

1.3.自然连接:在连接条件中使用等于(=)运算符比较被连接列的列值,但它使用选择列表指出查询结果集合中所包括的列,并删除连接表中的重复列。

内连接:内连接查询操作列出与连接条件匹配的数据行,它使用比较运算符比较被连接列的列值。
2.1.左联接:是以左表为基准,将a.stuid = b.stuid的数据进行连接,然后将左表没有的对应项显示,右表的列为NULL
2.2.右连接:是以右表为基准,将a.stuid = b.stuid的数据进行连接,然以将右表没有的对应项显示,左表的列为NULL

子查询
select * from customer where id >(select avg(id) from customer);
select * from customer where id in (select cus_id from address);

猜你喜欢

转载自blog.csdn.net/qq_31844775/article/details/82490809