zoukankan      html  css  js  c++  java
  • 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 编码 )

     
  • 相关阅读:
    周记(2015-11-30 -- 2015-12-05)
    周记(2015-11-22 -- 2015-11-27)
    周记(2015-11-15 -- 2015-11-20)
    周记(2015-11-01 -- 2015-11-06)
    设备与主机的攻击日志类型分析总结
    OWASP十大攻击类型详解
    乌云TOP 10 简单介绍
    《启示录》读书笔记三
    百度地图和定位
    获取Android studio的SHA1值
  • 原文地址:https://www.cnblogs.com/xianyv/p/11556271.html
Copyright © 2011-2022 走看看