查询操作
1、别名查询
select id 序号,name名字from test_1209ryc;
2、条件查询(between)
select * from test_1209ryc where id between 2 and 5;
3、条件查询(in)
select * from test_1209ryc where id in(1,2,3);
4、子查询
select * from test_1209ryc where id in (select id from test_1209ryc where id>=5);
5、与或非的查询
select id from test_1209ryc where id >=4 and id <= 6;
select * from test_1209ryc where id>=5 and name = "qian";
select * from test_1209ryc where id>=5 or name = "qian;
select * from test_1209ryc where name="zhang" or name = "qian;
6、排序查询
select * from test_1209ryc order by id desc;
默认升序的
select * from test_1209ryc order by id;
select * from test_1209ryc order by id asc;
7、多列排序查询
(前面字段一样的时候,后面的字段在进行排序)
select * from test_1209ryc order by id,age asc;
8、仅返回一条数据
select * from test_1209ryc order by id,age asc limit 1;
9、limit 5,1(跳过5行,显示1行)
select * from test_1209ryc order by id,age asc limit 5,1;
(跳过5行,显示1行)
10、去重distinct
select distinct name 名字 from test_1209ryc;
11、统计总数(count)
select count(name) 名字from test_1209ryc;
12、统计平均值(avg)
select avg(age) 年龄 from test_1209ryc;
13、查看当前时间戳select now()
select now()
查看当前时间(服务器的时间)
select now();
14、查看当前时间select curtime()
select curtime();
15、分组查询
select count(*),age from test_1209ryc group by age;
分组里面的条件只能用having,使用Where会报错