zoukankan      html  css  js  c++  java
  • 数据库操纵

    一. 查找重复记录



      1. 查找全部重复记录

    Select * From 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)



      2. 过滤重复记录(只显示一条)

    Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)

    注:此处显示ID最大一条记录



      二. 删除重复记录



      1. 删除全部重复记录(慎用)

    Delete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)



      2. 保留一条(这个应该是大多数人所需要的)

    Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)

      注:此处保留ID最大一条记录



    删除表中指定的行


    delete from 表名 where rowid in (select rowid from 表名 order by 字断 desc limit 条数 offset 从第几行)



    清空表数据,与册除表

    "TRUNCATE table '表名'"; "drop table '表名'";



    查找的字断是字串时用法如下

    sprintf(sql, "SELECT * FROM GroupTable where gid=='%s' ORDER BY gid asc", [gid UTF8String]);



    并列条件如下:

    sprintf(sql, "SELECT * FROM FriendTable where type==%d AND uid==%s ORDER BY name asc",type, [uidUTF8String]);



    获取所有字断中如果重复就可获取一条最小的ID

    sprintf(sql, "SELECT * FROM CarTable where Id In (SELECT Min(Id) form CarTable Group By 字断) ORDER BY carId asc");

  • 相关阅读:
    Python shutil模块
    Flask 上传文件
    Flask DBUtils
    flash-session
    Flash 上下文管理
    python 栈
    python 偏函数
    threding.local
    next() 与 nextLine() 区别
    Thread.sleep(1000*3); // 休眠3秒
  • 原文地址:https://www.cnblogs.com/mumoozhu/p/4582833.html
Copyright © 2011-2022 走看看