您的位置:首页 > 其它

简单的数据查询

2016-01-09 00:24 309 查看
简单的数据查询
简单的查询语句

select * from 

投影操作

seleact 列1,列2 from 表名

列名列表几种书写方式:

1.如果我们选择某个表中的多个列,那么列名之间用逗号分隔开;

2.如果是单个列,只需要列出该列的列名即可;

3.如果选择所有的列,可以简单的用“*”号带代替列名列表。

如何查询

select 姓名,年龄 from t_student

表前缀:

select t_student.(要操作哪一个表的表名)姓名 from t_stuent

列别名

select concat(t_name,'_',t_address)AS'公司名字和地址' from gongsi;其中AS可以省略

计算列

列如:将每个学生年龄加十

select 年龄(t_age)+10 from 表名 

排除重复数据

select distinct 列 from 表

选择操作(where ,limit)

返回限定行数的查询

控制返回的行:select * from gongsi where t_id>=2 and t_id<=3;

select * from gongsi LIMIT 2;从0开始  有前2条(limit序号是从0开始的)

选择操作(where)

查询公司在绵阳的:select * from gongsi where t_address='绵阳';

执行范围测试(between   and)

select * from 列1 where 列2 between 12 and 20;(包含12和20)

查询集合

select * from yuangong where t_age in[not in(不等于)](18,19,20);

模糊查询(like)

select * from yuangong where t_name like '王%'(表示以王开头的)

[‘%青’(表示以青结尾的)]

‘__’(表示为两个字的)

‘x%n_’(表示以x开始倒数第二为n的)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: