Sqlite3 sqlalchemy技巧

sqlite 删除表中重复数据(亲测可用)

 例子:表名  Paper 。通过字段PaperID查找重复数据。  

 1 --查询某表中重复的数据
       select * from Paper group by PaperID having count(*)>1;

 2--删除重复行数,只剩不重复的记录(rowid为sqlite自带字段)
      delete from Paper where Paper.rowid not in (select MAX(Paper.rowid) from Paper group by PaperID);

使用Sqlacodegen 来生成符合sqlalchemy的model类

sqlacodegen sqlite:///database --outfile datamodel.py


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.7.0

@2021 yunfeng.net.cn 版权所有
浙ICP备16007973号-1