当前位置:首页 » Mysql技术教程

MySQL----查

2017-08-02 15:01 本站整理 浏览(2)

数据库在我眼中就是增删改查,而查,我觉得是数据库最费劲的,数据库的花式查,各种查。下面咱们不废话,就是干。

查:

**查数据库版本**
select version();
**查登录用户**
select user();
**查库中有多少数据库**
show databases;
**切换到数据库中**
use xxx(database name);
**查库中有多少表**
show tables;
**查表中的内容**
select * from xxx(表名);
`*`的意思是统配所有,也可以写具体的表中的title,如name,id等等。

# 排序
select * from tb12 order by id desc; 大到小
select * from tb12 order by id asc; 小到大
取后10条数据
select * from tb12 order by id desc limit 10;
# 分页
select * from tb12 limit 10;
select * from tb12 limit 0,10;
select * from tb12 limit 10,10;
select * from tb12 limit 20,10;
select * from tb12 limit 10 offset 20;

page = input('请输入要查看的页码')
page = int(page)
(page-1) * 10
select * from tb12 limit 0,10; 1
select * from tb12 limit 10,10;2

# 通配符
select * from tb12 where name like "a%"
select * from tb12 where name like "a_"

select * from tb12;
select id,name from tb12;
select id,name from tb12 where id > 10 or name ='xxx';
select id,name as cname from tb12 where id > 10 or name ='xxx';
select name,age,11 from tb12;
select * from tb12 where id != 1
select * from tb12 where id in (1,5,12);
select * from tb12 where id not in (1,5,12);
select * from tb12 where id in (select id from tb11)
select * from tb12 where id between 5 and 12;