SQL基本函数

学习书籍:《MySq必知必会》 pdf版本没有可以在评论留下邮箱,我会私发

1.检索

(1)Select instinct:查询值去重
(2)Limit 5:写到最后,限制返回的行数
(3)Limit 5,5:返回第5行后的5行

2.排序

(1)限制+排序,eg .求max/min:order by… limit 1

3.过渡

(1)Where:<>,!=
(2)Between:在范围内
(3)Is null 空值
(4)Where A and/or b 可用()圆括号提高优先级
(5)Where A in (1,2,3…10)or
(6)Where A not in …

4.通配符

(1)Where A like ‘a%’:%多个字符, _单个字符
e.g:寻找衍生词 customer_searchterm LIKE %gymnastics mat%;%gymnastics mat;gymnastics mat%;%gymnastics%mat%

5.正则表达式(不区分大小写)

(1)Where A regexp … :单个字符
(2)Where A regexp binary:区分大小写
(3)Gegexp ‘1000/2000’ ≈or 可用多个

6.正则

(1)匹配特定字符:’[123]TON’1or2or3TON
(2)匹配范围:[1-5]
(3)匹配特殊字符
(4)转移\
(5)重复元字符:*:0个/多个;+:1个/多个;?:0个/1个;{n, m}:n-m个
Eg:4个数字[[::digit:]]{4} or [0-9][0-9][0-9][0-9]

7.计算字段(平常叫列,计算要叫字段)

(1)拼接concat(a,b)
(2)去空格Trim(), Ltrim(),Rtrim()
(3)乘法:select A*B as C

8.函数

(1)Length()
(2)Locate():字符串子串位置
(3)Upper():全大写
(4)Substring():返回子串

9.日期函数

(1)CurDate():现在日期
(2)yyyy-mm-dd形式
(3)eg:选择2005年9月
where date(order,date) between ‘2005-09-01’ and ‘2005-09-30’
where year(order,date)=2005 and month(order_date)=9

10.分组

(1)Group by: select 针对每个组,不是结果集
(2)过滤分组:having, 针对组,用having,不用where,用法一样

11.联结

(1)Where A.id=B.id
(2)笛卡尔积(等值连接):C行数=A行数*B行数
(3)内联结: inner join,数据交集【常用】
(4)可用联结表替代子嵌套(select… where(select…))
(5)自联结:from products as p1, products as p2 where p1.id=p2.id
(6)外部联结:left outer join

12.组合查询

(1)Union:每条select之间用union联结,自动去重,不去用union all。

13.语句优先级(从先到后)

(1)Select
(2)Where
(3)Union
(4)Select
(5)where

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值