MySQL知识点
1.查看所有的数据库
show databases;
2.进入某个数据库
use 数据库名;
3.查看数据库里的全部表名
show tables;
4.查看某个表的结构
describe 表名;
5.修改数据
update 表名 set 列名 where 限制条件;
6.过滤表中重复的元素
select distinct 列名 from 表名;
7.使用别名表示列名
select 列名 "别名" from 表名;
8.查询一个属性的多种情况(具体值)
select * from 表名 where 列名=xx or 列名=xxx;
select * from 表名 where 列名 in (可能的属性值);
9.查询一个属性的一个范围
select * from 表名 where 列名>xx and 列名<xxx;
select * from 表名 where 列名 between xx and xxx;
10.查询所有姓李的属性(%表示0或多个字符)模糊查询
select * from 表名 where 列名 like '李%';
%李,代表名为李的数据,%李%代表名字中有李的数据
11.查询所有姓李的且名字为三个字的属性(_表示一个字符)
select * from 表名 where 列名 like '李__';
12.按某个属性进行降序查询
select * from 表名 order by 列名 desc;
13.查询总数 count
select count(*) "别名" from 表名;(不建议用*,用非null的列名最好,即主键)
select count(distinct 列名) "别名" from 表名;
14.统计某一列的元素和 sum
select sum(列名) from 表名;
select sum(distinct 列名) from 表名;(统计不重复元素的总和)
15.求平均值 avg
select avg(列名) from 表名;
16.求最大最小值
select max(列名) from admin;
select min(列名) from admin;
select * from 表名 where 列名=(select max(列名) from 表名)
17.

浙公网安备 33010602011771号