重修課程day41(mysql五之表的查看操作)
一 補充一些雜碎的知識
1 插入數據:
create table 新表名(字段 數據類型[約束條間]。。。) select 字段。。。 from 舊表名
create table 新表名(字段 數據類型[約束條件]。。。) select 字段 as 別名 from 舊表名 [where 條件];
as 起一個別名,起別名時,默認有as 所以可以不用加as 就可以起別名。
mysql> create table t1(id int primary key auto_increment, -> name char(10) not null, -> age int not null); Query OK, 0 rows affected (0.38 sec) mysql> insert into t1(name,age)values(‘fang‘,18),(‘haiyan‘,17),(‘dong‘,21); Query OK, 3 rows affected (0.06 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> desc t1; +-------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | char(10) | NO | | NULL | | | age | int(11) | NO | | NULL | | +-------+----------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) mysql> select * from t1; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 1 | fang | 18 | | 2 | haiyan | 17 | | 3 | dong | 21 | +----+--------+-----+ 3 rows in set (0.00 sec) mysql> create table t2(name char(10) not null, -> age int not null) select name,age from t1; Query OK, 3 rows affected (0.32 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> desc t2; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | name | char(10) | NO | | NULL | | | age | int(11) | NO | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> select * from t2; +--------+-----+ | name | age | +--------+-----+ | fang | 18 | | haiyan | 17 | | dong | 21 | +--------+-----+ 3 rows in set (0.00 sec) mysql> create table t3(x char(10) not null, -> a int not null) select name as x,age a from t1; Query OK, 3 rows affected (0.31 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> desc t3; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | x | char(10) | NO | | NULL | | | a | int(11) | NO | | NULL | | +-------+----------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> select * from t3; +--------+----+ | x | a | +--------+----+ | fang | 18 | | haiyan | 17 | | dong | 21 | +--------+----+ 3 rows in set (0.00 sec)
2 修改數據:
update 表名 set 字段=記錄 where 條件;
mysql> create table t1(id int primary key auto_increment, -> name char(10) not null, -> age int not null); Query OK, 0 rows affected (0.38 sec) mysql> insert into t1(name,age)values(‘fang‘,18),(‘haiyan‘,17),(‘dong‘,21); Query OK, 3 rows affected (0.06 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> desc t1; +-------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | char(10) | NO | | NULL | | | age | int(11) | NO | | NULL | | +-------+----------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) mysql> select * from t1; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 1 | fang | 18 | | 2 | haiyan | 17 | | 3 | dong | 21 | +----+--------+-----+ 3 rows in set (0.00 sec) mysql> update t1 set name=‘jie‘ where id=3 and age=21; Query OK, 1 row affected (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from t1; +----+--------+-----+ | id | name | age | +----+--------+-----+ | 1 | fang | 18 | | 2 | haiyan | 17 | | 3 | jie | 21 | +----+--------+-----+ 3 rows in set (0.00 sec)
3 雜碎的內容:
concat:字符串的拼接,可以拼成任意的格式
concat_ws:第一個參數指定的是分割符,後面加上自己要看的字段
\G:將亂了的記錄重新按行顯示。
二 常用的select查看
select 的基本格式:
select distinot:去重 字段名。。。 from 表名
where 約束條件 :取出來的記錄默認為是一個組,在這裏就可以使用聚合函數,約束條件就是默認某些字段的約束。
group by 字段名 :後面加上某個字段,就會按照那個字段分組,分組過後可以直接查看分組的字段,要想查看其他的字段,必須要借助聚合函數,分組是為了一類一類的處理數據。而分組的字段是依據字段的約束條件不唯一。
having 過濾語句 :只能跟在分組的後面,處理一些分組過後的約束條件。
order by 字段 排序 :排序。後面加上需要按照排序的字段,後面可以同時加上多個排序條件,如果前面的排序有重復的,才會執行後面的,如果沒有重復的,後面的就不會執行。他是在取出了相應字段的記錄後才開始執行的。
limit 限制條件 :規定查看的範圍,在最後才開始運行。
準備表:
mysql> use day44; Database changed mysql> create table employee( -> id int not null unique auto_increment, -> name varchar(20) not null, -> sex enum(‘male‘,‘female‘) not null default ‘male‘, #大部分是男的 -> age int(3) unsigned not null default 28, -> hire_date date not null, -> post varchar(50), -> post_comment varchar(100), -> salary double(15,2), -> office int, #一個部門一個屋子 -> depart_id int -> ); Query OK, 0 rows affected (0.28 sec) mysql> mysql> mysql> #查看表結構 mysql> desc employee; +--------------+-----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+-----------------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | NO | | NULL | | | sex | enum(‘male‘,‘female‘) | NO | | male | | | age | int(3) unsigned | NO | | 28 | | | hire_date | date | NO | | NULL | | | post | varchar(50) | YES | | NULL | | | post_comment | varchar(100) | YES | | NULL | | | salary | double(15,2) | YES | | NULL | | | office | int(11) | YES | | NULL | | | depart_id | int(11) | YES | | NULL | | +--------------+-----------------------+------+-----+---------+----------------+ 10 rows in set (0.01 sec) mysql> mysql> #插入記錄 mysql> #三個部門:教學,銷售,運營 mysql> insert into employee(name,sex,age,hire_date,post,salary,office,depart_id) values -> (‘egon‘,‘male‘,18,‘20170301‘,‘老男孩駐沙河辦事處外交大使‘,7300.33,401,1), #以下是教學部 -> (‘alex‘,‘male‘,78,‘20150302‘,‘teacher‘,1000000.31,401,1), -> (‘wupeiqi‘,‘male‘,81,‘20130305‘,‘teacher‘,8300,401,1), -> (‘yuanhao‘,‘male‘,73,‘20140701‘,‘teacher‘,3500,401,1), -> (‘liwenzhou‘,‘male‘,28,‘20121101‘,‘teacher‘,2100,401,1), -> (‘jingliyang‘,‘female‘,18,‘20110211‘,‘teacher‘,9000,401,1), -> (‘jinxin‘,‘male‘,18,‘19000301‘,‘teacher‘,30000,401,1), -> (‘成龍‘,‘male‘,48,‘20101111‘,‘teacher‘,10000,401,1), -> -> (‘歪歪‘,‘female‘,48,‘20150311‘,‘sale‘,3000.13,402,2),#以下是銷售部門 -> (‘丫丫‘,‘female‘,38,‘20101101‘,‘sale‘,2000.35,402,2), -> (‘丁丁‘,‘female‘,18,‘20110312‘,‘sale‘,1000.37,402,2), -> (‘星星‘,‘female‘,18,‘20160513‘,‘sale‘,3000.29,402,2), -> (‘格格‘,‘female‘,28,‘20170127‘,‘sale‘,4000.33,402,2), -> -> (‘張野‘,‘male‘,28,‘20160311‘,‘operation‘,10000.13,403,3), #以下是運營部門 -> (‘程咬金‘,‘male‘,18,‘19970312‘,‘operation‘,20000,403,3), -> (‘程咬銀‘,‘female‘,18,‘20130311‘,‘operation‘,19000,403,3), -> (‘程咬銅‘,‘male‘,18,‘20150411‘,‘operation‘,18000,403,3), -> (‘程咬鐵‘,‘female‘,18,‘20140512‘,‘operation‘,17000,403,3) -> ; Query OK, 18 rows affected (0.09 sec) Records: 18 Duplicates: 0 Warnings: 0
集合函數:min:最小值 max:最大值 avg:計算平均值 sum:計算總和 count:計算個數
where 條件約束:後面可以加上比較符號(> < = != <> <= >=) 邏輯運算符(and or not)
in:什麽或什麽或什麽 between:在什麽和什麽之間 like:像什麽 後面出入兩個符號 % :任意多個字符 _ :表示任意一個字符 is:什麽是什麽
mysql> select * from employee where age>50; +----+---------+------+-----+------------+---------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+---------+------+-----+------------+---------+--------------+------------+--------+-----------+ | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | | 3 | wupeiqi | male | 81 | 2013-03-05 | teacher | NULL | 8300.00 | 401 | 1 | | 4 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 | +----+---------+------+-----+------------+---------+--------------+------------+--------+-----------+ 3 rows in set (0.00 sec) mysql> select * from employee where sex=‘male‘ and salary>30000; +----+------+------+-----+------------+---------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------+------+-----+------------+---------+--------------+------------+--------+-----------+ | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | +----+------+------+-----+------------+---------+--------------+------------+--------+-----------+ 1 row in set (0.00 sec) mysql> select * from employee where post=‘teacher‘ or salary>30000; +----+------------+--------+-----+------------+---------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------------+--------+-----+------------+---------+--------------+------------+--------+-----------+ | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | | 3 | wupeiqi | male | 81 | 2013-03-05 | teacher | NULL | 8300.00 | 401 | 1 | | 4 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 | | 5 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 | | 6 | jingliyang | female | 18 | 2011-02-11 | teacher | NULL | 9000.00 | 401 | 1 | | 7 | jinxin | male | 18 | 1900-03-01 | teacher | NULL | 30000.00 | 401 | 1 | | 8 | 成龍 | male | 48 | 2010-11-11 | teacher | NULL | 10000.00 | 401 | 1 | +----+------------+--------+-----+------------+---------+--------------+------------+--------+-----------+ 7 rows in set (0.00 sec) mysql> select * from employee where age between 20 and 30; +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ | 5 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 | | 13 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 | | 14 | 張野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 | +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ 3 rows in set (0.01 sec) mysql> select * from employee where id in(3,6,16) or name like ‘程%‘; +----+------------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ | 3 | wupeiqi | male | 81 | 2013-03-05 | teacher | NULL | 8300.00 | 401 | 1 | | 6 | jingliyang | female | 18 | 2011-02-11 | teacher | NULL | 9000.00 | 401 | 1 | | 15 | 程咬金 | male | 18 | 1997-03-12 | operation | NULL | 20000.00 | 403 | 3 | | 16 | 程咬銀 | female | 18 | 2013-03-11 | operation | NULL | 19000.00 | 403 | 3 | | 17 | 程咬銅 | male | 18 | 2015-04-11 | operation | NULL | 18000.00 | 403 | 3 | | 18 | 程咬鐵 | female | 18 | 2014-05-12 | operation | NULL | 17000.00 | 403 | 3 | +----+------------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ 6 rows in set (0.44 sec)
group by 分組:後面加上一個字段名
mysql> select post,count(id),group_concat(name) from employee group by post; +----------------------------+-----------+-------------------------------------------------------+ | post | count(id) | group_concat(name) | +----------------------------+-----------+-------------------------------------------------------+ | operation | 5 | 張野,程咬金,程咬銀,程咬銅,程咬鐵 | | sale | 5 | 歪歪,丫丫,丁丁,星星,格格 | | teacher | 7 | alex,wupeiqi,yuanhao,liwenzhou,jingliyang,jinxin,成龍 | | 老男孩駐沙河辦事處外交大使 | 1 | egon | +----------------------------+-----------+-------------------------------------------------------+ 4 rows in set (0.00 sec) mysql> select post,min(salary) from employee group by post; +----------------------------+-------------+ | post | min(salary) | +----------------------------+-------------+ | operation | 10000.13 | | sale | 1000.37 | | teacher | 2100.00 | | 老男孩駐沙河辦事處外交大使 | 7300.33 | +----------------------------+-------------+ 4 rows in set (0.00 sec) mysql> select post,max(salary) from employee group by post; +----------------------------+-------------+ | post | max(salary) | +----------------------------+-------------+ | operation | 20000.00 | | sale | 4000.33 | | teacher | 1000000.31 | | 老男孩駐沙河辦事處外交大使 | 7300.33 | +----------------------------+-------------+ 4 rows in set (0.00 sec) mysql> select post,sum(salary) from employee group by post; +----------------------------+-------------+ | post | sum(salary) | +----------------------------+-------------+ | operation | 84000.13 | | sale | 13001.47 | | teacher | 1062900.31 | | 老男孩駐沙河辦事處外交大使 | 7300.33 | +----------------------------+-------------+ 4 rows in set (0.00 sec) mysql> select post,avg(salary) from employee group by post; +----------------------------+---------------+ | post | avg(salary) | +----------------------------+---------------+ | operation | 16800.026000 | | sale | 2600.294000 | | teacher | 151842.901429 | | 老男孩駐沙河辦事處外交大使 | 7300.330000 | +----------------------------+---------------+ 4 rows in set (0.00 sec)
having 過濾條件:後面加的內容和where一樣的,不過需要借助於聚合函數過濾記錄
mysql> select post from employee group by post having count(id)>5; +---------+ | post | +---------+ | teacher | +---------+ 1 row in set (0.00 sec) mysql> select post from employee group by post having count(id)>5 or avg(salary) >10000; +-----------+ | post | +-----------+ | operation | | teacher | +-----------+ 2 rows in set (0.00 sec)
order by :後面跟上:asc:升序,從小到大排序 ; desc:降序,從大到小排序。order by:默認是從小到達排序的。
mysql> select * from employee order by age asc,id desc; +----+------------+--------+-----+------------+----------------------------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------------+--------+-----+------------+----------------------------+--------------+------------+--------+-----------+ | 18 | 程咬鐵 | female | 18 | 2014-05-12 | operation | NULL | 17000.00 | 403 | 3 | | 17 | 程咬銅 | male | 18 | 2015-04-11 | operation | NULL | 18000.00 | 403 | 3 | | 16 | 程咬銀 | female | 18 | 2013-03-11 | operation | NULL | 19000.00 | 403 | 3 | | 15 | 程咬金 | male | 18 | 1997-03-12 | operation | NULL | 20000.00 | 403 | 3 | | 12 | 星星 | female | 18 | 2016-05-13 | sale | NULL | 3000.29 | 402 | 2 | | 11 | 丁丁 | female | 18 | 2011-03-12 | sale | NULL | 1000.37 | 402 | 2 | | 7 | jinxin | male | 18 | 1900-03-01 | teacher | NULL | 30000.00 | 401 | 1 | | 6 | jingliyang | female | 18 | 2011-02-11 | teacher | NULL | 9000.00 | 401 | 1 | | 1 | egon | male | 18 | 2017-03-01 | 老男孩駐沙河辦事處外交大使 | NULL | 7300.33 | 401 | 1 | | 14 | 張野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 | | 13 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 | | 5 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 | | 10 | 丫丫 | female | 38 | 2010-11-01 | sale | NULL | 2000.35 | 402 | 2 | | 9 | 歪歪 | female | 48 | 2015-03-11 | sale | NULL | 3000.13 | 402 | 2 | | 8 | 成龍 | male | 48 | 2010-11-11 | teacher | NULL | 10000.00 | 401 | 1 | | 4 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 | | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | | 3 | wupeiqi | male | 81 | 2013-03-05 | teacher | NULL | 8300.00 | 401 | 1 | +----+------------+--------+-----+------------+----------------------------+--------------+------------+--------+-----------+ 18 rows in set (0.00 sec)
limit 限制條件:後面輸入整數類型,只傳一個值是查看記錄的條數,默認從第1條記錄開始查看,如果出入兩個數,第一個數是初始值,就是從那一條的下一條開始查看,第二個數就是查看記錄的條數。
mysql> select * from employee where id limit 6,10; +----+--------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+--------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ | 7 | jinxin | male | 18 | 1900-03-01 | teacher | NULL | 30000.00 | 401 | 1 | | 8 | 成龍 | male | 48 | 2010-11-11 | teacher | NULL | 10000.00 | 401 | 1 | | 9 | 歪歪 | female | 48 | 2015-03-11 | sale | NULL | 3000.13 | 402 | 2 | | 10 | 丫丫 | female | 38 | 2010-11-01 | sale | NULL | 2000.35 | 402 | 2 | | 11 | 丁丁 | female | 18 | 2011-03-12 | sale | NULL | 1000.37 | 402 | 2 | | 12 | 星星 | female | 18 | 2016-05-13 | sale | NULL | 3000.29 | 402 | 2 | | 13 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 | | 14 | 張野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 | | 15 | 程咬金 | male | 18 | 1997-03-12 | operation | NULL | 20000.00 | 403 | 3 | | 16 | 程咬銀 | female | 18 | 2013-03-11 | operation | NULL | 19000.00 | 403 | 3 | +----+--------+--------+-----+------------+-----------+--------------+----------+--------+-----------+ 10 rows in set (0.00 sec)
他們的執行順序是:from——》where—》group by—》having—》distinct—》order—》limit。如果上一個沒有順序還是不會改變
distinct:去掉重復
only_full_group_by:使用方法 set @@lobal sql_mode=‘only_full_group_by‘ 修改全局的一條信息
where後面還可以跟上regexp:正則表達式條件約束,regexp後面跟的內容和正則表達式裏面的內容差不多
mysql> select * from employee where name regexp ‘a.‘; +----+------------+--------+-----+------------+---------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------------+--------+-----+------------+---------+--------------+------------+--------+-----------+ | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | | 4 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 | | 6 | jingliyang | female | 18 | 2011-02-11 | teacher | NULL | 9000.00 | 401 | 1 | +----+------------+--------+-----+------------+---------+--------------+------------+--------+-----------+ 3 rows in set (0.05 sec) mysql> select * from employee where name regexp ‘a*‘; +----+------------+--------+-----+------------+----------------------------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------------+--------+-----+------------+----------------------------+--------------+------------+--------+-----------+ | 1 | egon | male | 18 | 2017-03-01 | 老男孩駐沙河辦事處外交大使 | NULL | 7300.33 | 401 | 1 | | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | | 3 | wupeiqi | male | 81 | 2013-03-05 | teacher | NULL | 8300.00 | 401 | 1 | | 4 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 | | 5 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 | | 6 | jingliyang | female | 18 | 2011-02-11 | teacher | NULL | 9000.00 | 401 | 1 | | 7 | jinxin | male | 18 | 1900-03-01 | teacher | NULL | 30000.00 | 401 | 1 | | 8 | 成龍 | male | 48 | 2010-11-11 | teacher | NULL | 10000.00 | 401 | 1 | | 9 | 歪歪 | female | 48 | 2015-03-11 | sale | NULL | 3000.13 | 402 | 2 | | 10 | 丫丫 | female | 38 | 2010-11-01 | sale | NULL | 2000.35 | 402 | 2 | | 11 | 丁丁 | female | 18 | 2011-03-12 | sale | NULL | 1000.37 | 402 | 2 | | 12 | 星星 | female | 18 | 2016-05-13 | sale | NULL | 3000.29 | 402 | 2 | | 13 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 | | 14 | 張野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 | | 15 | 程咬金 | male | 18 | 1997-03-12 | operation | NULL | 20000.00 | 403 | 3 | | 16 | 程咬銀 | female | 18 | 2013-03-11 | operation | NULL | 19000.00 | 403 | 3 | | 17 | 程咬銅 | male | 18 | 2015-04-11 | operation | NULL | 18000.00 | 403 | 3 | | 18 | 程咬鐵 | female | 18 | 2014-05-12 | operation | NULL | 17000.00 | 403 | 3 | +----+------------+--------+-----+------------+----------------------------+--------------+------------+--------+-----------+ 18 rows in set (0.00 sec) mysql> select * from employee where name regexp ‘^a.‘; +----+------+------+-----+------------+---------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------+------+-----+------------+---------+--------------+------------+--------+-----------+ | 2 | alex | male | 78 | 2015-03-02 | teacher | NULL | 1000000.31 | 401 | 1 | +----+------+------+-----+------------+---------+--------------+------------+--------+-----------+ 1 row in set (0.00 sec) mysql> select * from employee where name regexp ‘^j.‘; +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+ | 6 | jingliyang | female | 18 | 2011-02-11 | teacher | NULL | 9000.00 | 401 | 1 | | 7 | jinxin | male | 18 | 1900-03-01 | teacher | NULL | 30000.00 | 401 | 1 | +----+------------+--------+-----+------------+---------+--------------+----------+--------+-----------+ 2 rows in set (0.00 sec) mysql> select * from employee where name regexp ‘^j.*n$‘; +----+--------+------+-----+------------+---------+--------------+----------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id | +----+--------+------+-----+------------+---------+--------------+----------+--------+-----------+ | 7 | jinxin | male | 18 | 1900-03-01 | teacher | NULL | 30000.00 | 401 | 1 | +----+--------+------+-----+------------+---------+--------------+----------+--------+-----------+ 1 row in set (0.00 sec)
重修課程day41(mysql五之表的查看操作)