可以经常看看 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');

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

常用函数

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条件表达式

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
版权声明:本文为博主原创文章,转载请附上博文链接!

[sql]sql的select字符串切割的更多相关文章

  1. sql存储过程exec执行字符串select 的区别

    USE [GuangHong]GO/****** Object: StoredProcedure [dbo].[st_MES_SelInspctDetail] Script Date: 11/23/2 ...

  2. SQL Server中截取字符串常用函数

    SQL Server 中截取字符串常用的函数: .LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要截 ...

  3. sql server 查找包含字符串的对象

    sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...

  4. 教您如何使用SQL中的SELECT LIKE like语句

    LIKE语句在SQL有着不可替代的重要作用,下文就将为您介绍SQL语句中SELECT LIKE like的详细用法,希望对您能有所帮助. LIKE语句的语法格式是:select * from 表名 w ...

  5. [置顶] VB6基本数据库应用(三):连接数据库与SQL语句的Select语句初步

    同系列的第三篇,上一篇在:http://blog.csdn.net/jiluoxingren/article/details/9455721 连接数据库与SQL语句的Select语句初步 ”前文再续, ...

  6. SQL Server 中截取字符串常用的函数

    SQL Server 中截取字符串常用的函数: 1.LEFT ( character_expression , integer_expression ) 函数说明:LEFT ( '源字符串' , '要 ...

  7. sql server中截取字符串的常用函数

    我们如果要在sql server中,使用截取字符串的方法要怎样使用呢? sql server提供了3个常用截取字符串方法,LEFT().RIGHT().SUBSTRING() /****** Sql ...

  8. Sql动态查询拼接字符串的优化

    Sql动态查询拼接字符串的优化 最原始的 直接写:string sql="select * from TestTables where 1=1";... 这样的代码效率很低的,这样 ...

  9. SQL Fundamentals: Basic SELECT statement基本的select语句(控制操作的现实列)(FROM-SELECT)

    SQL Fundamentals || Oracle SQL语言 Capabilities of the SELECT Statement(SELECT语句的功能) Data retrieval fr ...

随机推荐

  1. Linux Performance tool

    https://www.tecmint.com/command-line-tools-to-monitor-linux-performance/ https://www.tecmint.com/lin ...

  2. Python AES_ECB_PKCS5加密代码

    https://blog.csdn.net/u010978840/article/details/79035463 ****************************************** ...

  3. case when then 中判断null的方法

    --下列SQL无效 SELECT CASE MAX(T.CREATE_TIME) WHEN NULL THEN TO_DATE('2019-03-05 00:00:01','yyyy-MM-dd hh ...

  4. windows ngix 安装 配置 使用

    参考版本nginx-1.10.3 一.常用命令 start nginx.exe                      //开启服务 nginx.exe -s stop                ...

  5. Android打开各种类型的文件方法总结

    很简单,通过调用系统的intent,我们可以打开各种文件,不熟悉的朋友可以了解下action.datatype.uri的相关知识. 通用方法如下: public static Intent openF ...

  6. application.properties配置文件

    SpringBoot可以识别两种格式的配置文件,分别是yml文件与properties文件,可以将application.properties文件换成application.yml applicati ...

  7. WordPress中默认文本编辑器替换成百度UEditor编辑器

    1.下载 下载地址: http://pan.baidu.com/s/1geNk19L 2.解压放到plugins目录下 3.插件启用

  8. WEB服务器与应用服务器的区别

    一.简述 WEB服务器与应用服务器的区别: 1.WEB服务器: 理解WEB服务器,首先要理解什么是WEB?WEB可以简单理解为我们所看到的HTML页面就是WEB的数据元素,处理这些数据元素的应用软件就 ...

  9. OSG相关扩展工程

    https://blog.csdn.net/wang15061955806/article/details/51003803 OSG的相关扩展,OSG针对每个特定应用,也有很多的开发者进行开发和完善, ...

  10. Git忽略已经被版本控制的文件(添加.gitignore不会起作用)

    说明:已经被维护起来的文件(需要被远程仓库控制),即使加入.gitignore也会无济于事. .gitignore只对那些只存在在本地,而不在远程仓库的文件起作用.(untraked file). 操 ...