sql

import pymysql

con = pymysql.connect(host="127.0.0.1",user="root",passwd="root",db="test")
cursor = con.cursor()

sql = "insert into test2(name,gender) select distinct name,gender from test1;"
cursor.execute(sql)


con.commit()

cursor.close()
con.close()

  name和gender同时不同才会取出。字段名称可以不一致,但是顺序绝对不能错。

 

sql = "alter table test1 alter moren set default 0;" # 设置默认值,但是之前的数据不会发生变更

  

sql = "update test1 set moren=0;"  # 原有数据全部设置为0

  

sql = "update test1 set moren=1,gender2='女';" # 设置多列

  

 

sql = "update test1 set moren=6 where name='张三';" # 条件更新

  

 

 

 

a = {"a":"a","b":"b","c":"c"}

a = json.dumps(a)
print(a)

a = json.loads(a)
print(a)


{"a": "a", "b": "b", "c": "c"}
{'a': 'a', 'b': 'b', 'c': 'c'}

  

 

 

 

 

 

 

 

 

posted @ 2019-12-03 00:23  real-admin  阅读(140)  评论(0编辑  收藏  举报