[sql]sql的select字符串切割

可以经常看看 mysql的refman,写的很棒

sql基础操作

查看表结构

show create table
desc table
show full columns from test1;

like语句

1. where id > 1 and name != 'maotai' order by id desc
2. where name like '%sre%'   # %任意长度 _任意单个字符,如 '_a_'    //三位且中间字母是a的
3. where id not in (11,22,33)
4. where id between 3 and 8
5. 查询空值

6. 通过正则
    select * from user where gender regexp '^(m|f)';

7, limit offset

SELECT * FROM t1 WHERE
  (key1 < 'abc' AND (key1 LIKE 'abcde%' OR key1 LIKE '%b')) OR
  (key1 < 'bar' AND nonkey = 4) OR
  (key1 < 'uux' AND key1 > 'z');

1312420-20181207173218862-909746977.png

mysql字段值长度为0和null的区别

1312420-20181207170237866-1190396515.png

1312420-20181207170252980-1321316506.png

常用函数

mysql> select max(age),min(age),sum(age),avg(age),count(age) from user;
+----------+----------+----------+----------+------------+
| max(age) | min(age) | sum(age) | avg(age) | count(age) |
+----------+----------+----------+----------+------------+
|       29 |       24 |      159 |  26.5000 |          6 |
+----------+----------+----------+----------+------------+
1 row in set (0.00 sec)


concat 字符串拼接
left: 保留字符串的前两位
mysql> select left('age',2);
+---------------+
| left('age',2) |
+---------------+
| ag            |
+---------------+
1 row in set (0.00 sec)

分组

mysql> select count(gender),gender,class from user group by class,gender;
+---------------+--------+-------+
| count(gender) | gender | class |
+---------------+--------+-------+
|             1 | female |     1 |
|             1 | male   |     1 |
|             1 | female |     2 |
|             1 | male   |     2 |
|             1 | female |     3 |
|             1 | male   |     3 |
+---------------+--------+-------+

select if条件表达式

1312420-20181207225310373-347233414.png

sql切割字符串

https://www.cnblogs.com/qiaoyihang/p/6270165.html

SELECT SPLIT_STR('a|bb|ccc|dd', '|', 3) as third;

+-------+
| third |
+-------+
| ccc   |
+-------+
str = 'www.baidu.com';

SELECT substring_index('www.baidu.com','.', 1);    #www

SELECT substring_index('www.baidu.com','.', 2);    #www.baidu

SELECT substring_index('www.baidu.com','.', -1);   #com

SELECT substring_index('www.baidu.com','.', -2);   #baidu.com

SELECT substring_index(substring_index('www.baidu.com','.', -2), '.', 1);  #baidu
--------------------- 
作者:来了就走下去 
来源:CSDN 
原文:https://blog.csdn.net/u012009613/article/details/52770567 
版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/iiiiiher/p/10083912.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值