数据库总结知识点(部分)

简单的数据查询: select 加字段名字 from 表位置

对查询结果进行排序:select 字段名 from 表位置 order by
需要排序的字段名(按照单词英文首字母)(加一个desc就是倒叙)

先按照第一次字段排完序,再按照第二个字段排序 :
select 字段名 from 表位置
order by字段名1 asc ,字段名2desc(字段顺序会影响排序顺序)

名字短前面,名字长后面:len() 这个关键字可以计算出有多少个字符
select 字段名 from 表位置
order by len(字段1) asc

查询限制语句,例如查找10行:关键字top
select top 10 字段名 from 表位置 (查找10行)
select top 10 percent 字段名 from 表位置 (查找百分之10)
order by

查询最贵的10行升序:select top 10 字段名 from 表位置
order by list_price

查询最贵的10行时,把最后一行都查询出来:select top 10 with ties 字段名 from
表位置 order by list_price

Offset Fetch语句可以查询几条到几条:
查找1-10行时:
select top 10 字段名 from 表位置
order by list_price
offset 0 rows//从第1行开始 第一页
fetch next 10 rows only
查找11-20行时第二页:
select top 10 字段名 from 表位置
order by list_price
offset 10 rows//从第11行开始
fetch next 10 rows only
公式:
select 字段名 from 表位置
order by 字段名
offset (页-1)*10 rows
fetch next 10 rows only

去重复distinct:select distinct 加字段名字 from 表位置
orderf by 字段名(先排序出来)

筛选一下字段不为空的信息:
select*from 表位置
where 字段 is not null
where phone=’1321523’//也可以直接查信息
where 字段名=‘dsfsdf’ and 字段名=‘sdjf’//查询两种
//数字可以用运算符

and和or 或者 and的优先级比or的要大
:select* from 表
Where 字段<=3000 or 字段>=5000 and 字段2=2017
Where 字段<=3000 or (字段>=5000 and 字段2=2017)//默认是这样的,因为and优先级高
Where (字段<=3000 or 字段>=5000 )and 字段2=2017

查找数值信息 in 关键字:
select *from 表名
where 字段名字 in(111,111)

模糊查询 like:
select *from 表名
where 字段名 like’a%’
where 字段名 like’_a%’ //第二个是字母a
where 字段名 like’__’ //单单查询两个字母
where 字段名 like’[abcde]%’ ,[a-c] //匹配abcde中的其全部任意字符

查找不是abc的
where 字段名 not like’[a-c]%’
where 字段名 like’[^a-c]%’ 两种写法

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值