SQL

in 笔记 with 0 comment

记性不好,每次都记不住百度,太浪费时间

分页查询

取前5条数据
select * from table_name limit 0,5 

查询第11到第15条数据
select * from table_name limit 10,5

多字段模糊查询

SELECT * FROM student WHERE concat(name,sex,age,classid,zhuanye) LIKE '%2%'

删除为null的字段(判空用is)

delete from table_name where openid is null
select * from people
where peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1)

神他吗for循环 自己瞎写的

-- 声明变量
declare @i int 
declare @max int
declare @str varchar(50)
-- 初始化 
set @i=1
set @max = (select count(*) from table_name)
while @i<=@max
begin

    set @str = 
    (
        select lpsqId from
        -- 给原表添加行标
        (select ROW_NUMBER() over(order by bbxrxm) row_num,* from table_name) t
        where t.row_num = @i
    )

    select @str
    set @i=@i +1
end
Responses