您的位置:首页 > 数据库 > MySQL

mysql 基本操作指南之mysql查询语句

2016-05-31 11:31 543 查看
1.show database;返回可用数据库的列表

2.show tables;返回当前数据库中可用表的列表

3.create database 数据库名称;

4.select * from 表名;  检索表的所有列数据

5.select id,name,price from 表名 order by name,price;  查询相关列信息并按name,price排序

6.select id,name,price from 表名 order by name desc,price;  查询相关列并按name降序,price默认升序排列

7.select id,name,price from 表名 order by name desc,price limit 1,3;  查询相关列并按name降序,price默认升序排列,从1开始取3条数据

8.select id,name,price from 表名 where name=' '; 根据条件查询数据

9.select id,name,price from 表名 where name IS NULL; 根据条件查询空值数据,多条件过滤时加AND 条件,加OR时表示匹配任意一条条件即可,

另外,当AND  和  OR子句共存在时,优先处理AND操作符子句:但是任何时候使用AND和OR操作符的WHERE子句都应该使用圆括号明确地分组操作符,

不要过分依赖默认的计算顺序

10.select id,name,price from 表名 where id IN () order by name; IN 操作符用来指定条件范围,范围内的每个条件都可以匹配 NOT IN ()反之

11.select id,name,price from 表名 where name LIKE '%na%'; 模糊查询操作符,小心使用

12.select name from 表名 where name REGEXP ' 正则表达式 ' order by name; 检索匹配相应规则的名字的信息,其中 . 匹配任意字符,\\.匹配.

13.select Concat(Tom,'(',jimmy,')') from table order by name;  拼接字符串 Tom(jimmy)

      其中:RTrim() 去掉串右边空格,LTrim() 去掉串左边空格,Trim() 去掉串左右两边空格

14.select pro_name,price*num as total from table where id=1; mysql支持+ - * /
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 数据库