标签:限制 最小值 特殊 ble tab 过滤 客户 rod rtrim(
show databases;//数据库列表
use databasename;//使用此数据库
show tables;//列表
show columns from tablename;//列出表属性的信息
describe tablenames;与上面等同
select columnname from tablename;//检索单个列
select column1,column2,column3 from tablename;//检索多个列
select * from tablename;//检索所有列
DISTINCT 检索出不同值的列
LIMIT 限制返回的行数
select column1 from tablename order by column1;//升序
select column1,column2 from tablename order by column1, column2;//多个列排序
select column1 from tablename order by column1 DESC;//降序
select column1 from tablename order by column1 ASC;//升序
使用ORDER BY 和LIMIT 可以找出列中最高或最低的值
SELECT COLUMN1 FROM TABLE1 ORDER BY COLUMN1 LIMIT 1;
WHERE搜索条件
select column1 from table1 where column1 = x;
select column1 from table1 where column1 between x1 and x2;//范围值检索
select column1 from table1 where column1 is null;//空值检索
组合WHERE子句,AND,OR
select column1, column2 from table1 where column1 = 1 and column2 = 2;//两个过滤条件
IN指定条件范围
select column1, column2 from table1 where column1 in (x1,x2) order by asc/desc;//在x1,x2范围内检索
NOT否定,配合IN
select column1 from table1 where column1 not in (x1,x2) order by column1;
LIKE谓词
%通配符,%为任意字符
select column1 from table1 where colomn1 LIKE 'jet%';//查找jet开头的词
_通配符,匹配单个字符
select column1 from table1 where column1 like '_ anvi1'//anvi1前只能匹配一个字符
过滤条件复杂,正则表达式更有效解决
关键字REGEXP
select column1 from table1 where column1 REGEXP '.000';//
从数据库中检索出转换、计算或者格式化过的数据,而不是在客户端应用程序重新格式化
拼接字段Concat(),把多个串连接起来
select Concat(column1 , '(', column2,")") from table1;//输出效果为column1(column2)
用AS关键字赋予别名,别名也称为导出列
SELECT datetime FROM table1 WHERE Date(datetime) = '2015-09-01';//过滤条件:日期20150901
汇总表的数据,确定表中行数,获得表中行组的和,找出最大值最小值
SELECT COUNT(*) AS num_items,
MIN(prod_price) AS price_min,
MAX(prod_price) AS price_max,
AVG(prod_price) AS price_avg
FROM products;
GROUP BY以什么分组
嵌套在其他查询中的查询
SELECT cust_id FROM orders WHERE order_num IN( SELECT order_num FROM orderitems WHERE prod_id = 'TNT2');
标签:限制 最小值 特殊 ble tab 过滤 客户 rod rtrim(
原文地址:https://www.cnblogs.com/chenshaowei/p/12395253.html