1explain select * from basetab_sg where RoleID in (select roleid from basetab_sg);
1select version();
1 2asc 升序 desc 降序
1 2 3SELECT length, count(id) FROM `db_mydomain_8` where length > 20 GROUP BY length; SELECT length, count(id) FROM `db_mydomain_8` where length > 20 GROUP BY length ORDER BY length desc;
1SELECT length, count(id) FROM `db_mydomain_8` where length > 20 GROUP BY length ORDER BY length desc limit 2, 1;
1SELECT * FROM `basetab_sg` as b inner join users as u on u.ID = b.AccountID;
左连接,包括左表全部记录
1select u.`name`, b.ProtectInfo from users as u left JOIN safetab_sg as b on u.ID = b.AccountID;
右连接,包括右表全部记录
_ 匹配单个字符
% 匹配任意字符
1SELECT * FROM `basetab_sg` as b inner join users as u on u.ID = b.AccountID where b.name like '_i%';
1select * from basetab_sg where name in (SELECT name from users where name in ('oppo', 'vivo'));
1select * from basetab_sg where EXISTS (SELECT name from users where name in ('nokia'));
count(field) 忽略NULL 3
count(*) 全部 4
1 2 3SELECT COUNT(truth) FROM `tbl_test` ; SELECT COUNT(truth) FROM `tbl_test` where truth is not null ;
1 2 3SELECT * FROM `users` where name regexp 'pp'; SELECT * FROM `users` where name regexp '^[o]';
+、-、*、/、%
1select 2*profession from basetab_sg limit 3;
= 等于
> 大于
< 小于
>= 大于等于
<= 小于等于
!=、<> 不等于
is null 判断是否null
is not null 判断是否不为null
between and 两者之间
in 在集合中
like 模糊匹配
not like 不像
greatest 返回最大参数
least 返回最小参数,有null返回null
regexp 正则匹配,有null返回null
1 2// 3 a select GREATEST(1, 2, 3), LEAST('a', 'b', 'c');
not、! 非
and、&& 与
or、|| 或
xor 异或,有null返回null,相同返回0
1select 1 xor null, 2 xor 2, 0 xor 1;
对二进制进行计算
& 位与
| 位或
~ 位反
^ 位异或
<< 位左移
>> 位右移
Copyright ©2010-2022 比特日记 All Rights Reserved.