• SQL server中常用sql语句


    --循环执行插入10000条数据

    declare @ID int
    begin
    set @ID=1

    while @ID<=10000
    begin
    insert into table_name values('','','')--要循环的sql语句
    set @ID=@ID+1
    end
    end

    --获取随机数

    select rand()--获取0~1之间的float型的数字

    DECLARE @NumBegin Int=60 --随机数的最小值
    DECLARE @NumEnd Int=100 --随机数的最大值
    DECLARE @Decimal Int=2 --保留小数点几位
    SELECT @NumBegin+round((@NumEnd-@NumBegin)*rand(),@Decimal)

    --删除表中数据,不可恢复

    truncate table table_name

    --查找重复数据

    select * from tablename
    where user_id in(select  user_id from tablename group by  user_id having COUNT(*)>1)
    order by  user_id 

     --删去重复的,只留下重复记录中编码最大的一条

    delete from 表名 where 

    编码 in(select 编码 from 表名 group by 编码 having count(1) >= 2) 

    and 编码 not in (select max(编码)from 表名 group by 编码 having count(1) >=2)
    --查找数据(排除重复数据)

    select * from [表名] where 编码 not in (
    select 编码 from [表名] where
    编码 in(select 编码 from [表名] group by 编码 having count(1) >= 2)
    and 编码 not in (select max(编码) from [表名] group by 编码 having count(1) >=2))

     或

    select * from [表名] where 自增主键 in (
    select max(自增主键) from [表名] group by 编码 )

     
  • 相关阅读:
    Python面向对象
    Python
    05、Win7上openSSH的安装与配置
    关于C++中的类型转换
    正确地使用智能指针
    为多态基类声明多态析构函数
    透视校正插值(Perspective-Correct Interpolation)
    保持const和non-const函数代码的一致
    第二章 信息的表示和处理
    《Linux内核分析》课程总结
  • 原文地址:https://www.cnblogs.com/xianyv/p/11556271.html
Copyright © 2020-2023  润新知