MySQL_查询操作(select)

查询操作

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;

 

9limit 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会报错

 

转载于:https://www.cnblogs.com/rychh/articles/11229410.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值