非等值连接 创建一张表 mysql> create table wage_grade -> ( -> id int, -> grade char(1), -> low int, -> high int, -> primary key(id)); Query OK, 0 rows affected (0.00 sec) 查看表 mysql> show tables; +-------------------+ | Tables_in_nsd2021 | +-------------------+ | departments | | employees | | salary | | wage_grade | +-------------------+ 4 rows in set (0.00 sec) 向表中插入数据 mysql> insert into wage_grade values -> (1,'A',5000,8000), -> (2,'B',8001,10000), -> (3,'C',10001,15000), -> (4,'D',15001,20000), -> (5,'E',20001,1000000); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0 查看表中数据 mysql> select -> * -> from wage_grade; +----+-------+-------+---------+ | id | grade | low | high | +----+-------+-------+---------+ | 1 | A | 5000 | 8000 | | 2 | B | 8001 | 10000 | | 3 | C | 10001 | 15000 | | 4 | D | 15001 | 20000 | | 5 | E | 20001 | 1000000 | +----+-------+-------+---------+ 5 rows in set (0.00 sec)
查询2018年员工基本工资级别 mysql> select -> employee_id,date,basic,bonus,grade -> from salary -> inner join wage_grade -> on basic between low and high -> where year(date)=2018 and month(date)=12 -> order by grade; +-------------+------------+-------+-------+-------+ | employee_id | date | basic | bonus | grade | +-------------+------------+-------+-------+-------+ | 51 | 2018-12-10 | 6076 | 1000 | A | | 97 | 2018-12-10 | 7292 | 1000 | A | | 133 | 2018-12-10 | 6076 | 7000 | A | | 87 | 2018-12-10 | 7292 | 5000 | A | | 111 | 2018-12-10 | 6076 | 3000 | A | | 64 | 2018-12-10 | 6076 | 2000 | A | | 89 | 2018-12-10 | 7292 | 5000 | A | | 30 | 2018-12-10 | 7292 | 8000 | A | | 55 | 2018-12-10 | 6076 | 5000 | A | | 90 | 2018-12-10 | 6076 | 1000 | A | | 101 | 2018-12-10 | 7292 | 9000 | A | | 114 | 2018-12-10 | 6076 | 3000 | A | | 18 | 2018-12-10 | 7292 | 2000 | A | | 83 | 2018-12-10 | 9724 | 1000 | B | | 130 | 2018-12-10 | 9724 | 11000 | B | | 26 | 2018-12-10 | 8507 | 5000 | B | | 109 | 2018-12-10 | 8507 | 11000 | B | | 3 | 2018-12-10 | 9724 | 8000 | B | | 121 | 2018-12-10 | 9724 | 7000 | B | | 41 | 2018-12-10 | 9724 | 9000 | B | | 77 | 2018-12-10 | 8507 | 11000 | B | | 67 | 2018-12-10 | 9724 | 9000 | B | | 82 | 2018-12-10 | 8507 | 8000 | B | | 116 | 2018-12-10 | 9724 | 11000 | B | | 93 | 2018-12-10 | 8507 | 2000 | B | | 69 | 2018-12-10 | 13369 | 4000 | C | | 22 | 2018-12-10 | 14585 | 1000 | C | | 59 | 2018-12-10 | 10938 | 6000 | C | | 94 | 2018-12-10 | 14585 | 6000 | C | | 129 | 2018-12-10 | 14585 | 7000 | C | | 70 | 2018-12-10 | 12154 | 3000 | C | | 84 | 2018-12-10 | 10938 | 7000 | C | | 60 | 2018-12-10 | 13369 | 10000 | C | | 72 | 2018-12-10 | 13369 | 4000 | C | | 50 | 2018-12-10 | 10938 | 6000 | C | | 96 | 2018-12-10 | 14585 | 11000 | C | | 132 | 2018-12-10 | 10938 | 11000 | C | | 39 | 2018-12-10 | 14585 | 5000 | C | | 120 | 2018-12-10 | 10938 | 3000 | C | | 74 | 2018-12-10 | 12154 | 8000 | C | | 14 | 2018-12-10 | 12154 | 5000 | C | | 15 | 2018-12-10 | 10938 | 10000 | C | | 43 | 2018-12-10 | 13369 | 5000 | C | | 65 | 2018-12-10 | 14585 | 9000 | C | | 100 | 2018-12-10 | 14585 | 11000 | C | | 44 | 2018-12-10 | 13369 | 6000 | C | | 78 | 2018-12-10 | 10938 | 10000 | C | | 113 | 2018-12-10 | 10938 | 1000 | C | | 124 | 2018-12-10 | 14585 | 9000 | C | | 45 | 2018-12-10 | 14585 | 10000 | C | | 115 | 2018-12-10 | 13369 | 7000 | C | | 126 | 2018-12-10 | 10938 | 11000 | C | | 9 | 2018-12-10 | 13369 | 2000 | C | | 47 | 2018-12-10 | 13369 | 8000 | C | | 58 | 2018-12-10 | 13369 | 11000 | C | | 107 | 2018-12-10 | 18231 | 7000 | D | | 11 | 2018-12-10 | 17016 | 8000 | D | | 49 | 2018-12-10 | 15800 | 9000 | D | | 95 | 2018-12-10 | 19448 | 8000 | D | | 1 | 2018-12-10 | 17016 | 7000 | D | | 108 | 2018-12-10 | 18231 | 2000 | D | | 12 | 2018-12-10 | 15800 | 4000 | D | | 85 | 2018-12-10 | 15800 | 1000 | D | | 73 | 2018-12-10 | 17016 | 10000 | D | | 13 | 2018-12-10 | 18231 | 3000 | D | | 62 | 2018-12-10 | 15800 | 4000 | D | | 110 | 2018-12-10 | 18231 | 2000 | D | | 52 | 2018-12-10 | 19448 | 9000 | D | | 28 | 2018-12-10 | 17016 | 9000 | D | | 63 | 2018-12-10 | 15800 | 8000 | D | | 98 | 2018-12-10 | 19448 | 9000 | D | | 4 | 2018-12-10 | 17016 | 2000 | D | | 99 | 2018-12-10 | 15800 | 5000 | D | | 5 | 2018-12-10 | 17016 | 3000 | D | | 123 | 2018-12-10 | 19448 | 10000 | D | | 6 | 2018-12-10 | 17016 | 1000 | D | | 17 | 2018-12-10 | 19448 | 7000 | D | | 66 | 2018-12-10 | 19448 | 7000 | D | | 79 | 2018-12-10 | 15800 | 4000 | D | | 125 | 2018-12-10 | 17016 | 5000 | D | | 32 | 2018-12-10 | 18231 | 11000 | D | | 46 | 2018-12-10 | 15800 | 7000 | D | | 81 | 2018-12-10 | 17016 | 3000 | D | | 20 | 2018-12-10 | 19448 | 3000 | D | | 92 | 2018-12-10 | 19448 | 2000 | D | | 21 | 2018-12-10 | 18231 | 11000 | D | | 127 | 2018-12-10 | 17016 | 6000 | D | | 34 | 2018-12-10 | 23093 | 1000 | E | | 106 | 2018-12-10 | 23093 | 5000 | E | | 10 | 2018-12-10 | 21878 | 8000 | E | | 48 | 2018-12-10 | 25524 | 1000 | E | | 117 | 2018-12-10 | 25524 | 11000 | E | | 37 | 2018-12-10 | 24309 | 4000 | E | | 118 | 2018-12-10 | 23093 | 3000 | E | | 25 | 2018-12-10 | 23093 | 3000 | E | | 38 | 2018-12-10 | 23093 | 3000 | E | | 119 | 2018-12-10 | 23093 | 10000 | E | | 61 | 2018-12-10 | 24309 | 3000 | E | | 2 | 2018-12-10 | 20662 | 9000 | E | | 86 | 2018-12-10 | 24309 | 4000 | E | | 27 | 2018-12-10 | 24309 | 5000 | E | | 40 | 2018-12-10 | 20662 | 2000 | E | | 76 | 2018-12-10 | 20662 | 11000 | E | | 53 | 2018-12-10 | 25524 | 8000 | E | | 88 | 2018-12-10 | 20662 | 2000 | E | | 122 | 2018-12-10 | 21878 | 2000 | E | | 29 | 2018-12-10 | 23093 | 1000 | E | | 112 | 2018-12-10 | 24309 | 9000 | E | | 16 | 2018-12-10 | 21878 | 8000 | E | | 54 | 2018-12-10 | 21878 | 9000 | E | | 31 | 2018-12-10 | 25524 | 9000 | E | | 7 | 2018-12-10 | 23093 | 4000 | E | | 56 | 2018-12-10 | 23093 | 3000 | E | | 91 | 2018-12-10 | 20662 | 11000 | E | | 102 | 2018-12-10 | 23093 | 3000 | E | | 8 | 2018-12-10 | 23093 | 2000 | E | | 57 | 2018-12-10 | 23093 | 3000 | E | | 33 | 2018-12-10 | 23093 | 6000 | E | | 68 | 2018-12-10 | 25524 | 9000 | E | | 105 | 2018-12-10 | 21878 | 8000 | E | +-------------+------------+-------+-------+-------+ 120 rows in set (0.03 sec) 查询2018年员工基本工资各级别的人数 mysql> select -> grade,count(*) -> from salary -> inner join wage_grade -> on basic between low and high -> where year(date)=2018 and month(date)=12 -> group by grade; +-------+----------+ | grade | count(*) | +-------+----------+ | A | 13 | | B | 12 | | C | 30 | | D | 32 | | E | 33 | +-------+----------+ 5 rows in set (0.01 sec) 查询2018年员工基本工资级别工资姓名 mysql> select -> s.employee_id,name,date,basic,bonus,grade -> from salary as s -> inner join wage_grade -> on basic between low and high -> inner join employees as e -> on e.employee_id=s.employee_id -> where year(date)=2018 and month(date)=12 -> order by grade; +-------------+-----------+------------+-------+-------+-------+ | employee_id | name | date | basic | bonus | grade | +-------------+-----------+------------+-------+-------+-------+ | 51 | 吴静 | 2018-12-10 | 6076 | 1000 | A | | 55 | 梁静 | 2018-12-10 | 6076 | 5000 | A | | 90 | 莫凤兰 | 2018-12-10 | 6076 | 1000 | A | | 18 | 戴璐 | 2018-12-10 | 7292 | 2000 | A | | 64 | 徐金凤 | 2018-12-10 | 6076 | 2000 | A | | 87 | 田萍 | 2018-12-10 | 7292 | 5000 | A | | 30 | 邢淑兰 | 2018-12-10 | 7292 | 8000 | A | | 114 | 黄秀云 | 2018-12-10 | 6076 | 3000 | A | | 89 | 唐芳 | 2018-12-10 | 7292 | 5000 | A | | 97 | 崔志强 | 2018-12-10 | 7292 | 1000 | A | | 101 | 李柳 | 2018-12-10 | 7292 | 9000 | A | | 111 | 赵凤兰 | 2018-12-10 | 6076 | 3000 | A | | 133 | 杨金凤 | 2018-12-10 | 6076 | 7000 | A | | 67 | 潘玲 | 2018-12-10 | 9724 | 9000 | B | | 77 | 吴丽娟 | 2018-12-10 | 8507 | 11000 | B | | 82 | 韩丹 | 2018-12-10 | 8507 | 8000 | B | | 116 | 贾荣 | 2018-12-10 | 9724 | 11000 | B | | 83 | 蒋秀芳 | 2018-12-10 | 9724 | 1000 | B | | 109 | 巫杨 | 2018-12-10 | 8507 | 11000 | B | | 121 | 孙婷 | 2018-12-10 | 9724 | 7000 | B | | 130 | 王玉兰 | 2018-12-10 | 9724 | 11000 | B | | 3 | 李玉英 | 2018-12-10 | 9724 | 8000 | B | | 26 | 党丽 | 2018-12-10 | 8507 | 5000 | B | | 41 | 陈玉 | 2018-12-10 | 9724 | 9000 | B | | 93 | 余春梅 | 2018-12-10 | 8507 | 2000 | B | | 9 | 张建平 | 2018-12-10 | 13369 | 2000 | C | | 22 | 吕刚 | 2018-12-10 | 14585 | 1000 | C | | 43 | 王波 | 2018-12-10 | 13369 | 5000 | C | | 47 | 黄建平 | 2018-12-10 | 13369 | 8000 | C | | 59 | 钟倩 | 2018-12-10 | 10938 | 6000 | C | | 72 | 赵杰 | 2018-12-10 | 13369 | 4000 | C | | 94 | 熊东 | 2018-12-10 | 14585 | 6000 | C | | 120 | 段杨 | 2018-12-10 | 10938 | 3000 | C | | 124 | 李慧 | 2018-12-10 | 14585 | 9000 | C | | 129 | 汤华 | 2018-12-10 | 14585 | 7000 | C | | 14 | 廖娜 | 2018-12-10 | 12154 | 5000 | C | | 39 | 张倩 | 2018-12-10 | 14585 | 5000 | C | | 44 | 黄文 | 2018-12-10 | 13369 | 6000 | C | | 60 | 贺磊 | 2018-12-10 | 13369 | 10000 | C | | 78 | 张娜 | 2018-12-10 | 10938 | 10000 | C | | 113 | 杨桂香 | 2018-12-10 | 10938 | 1000 | C | | 15 | 窦红梅 | 2018-12-10 | 10938 | 10000 | C | | 45 | 陈刚 | 2018-12-10 | 14585 | 10000 | C | | 65 | 张淑英 | 2018-12-10 | 14585 | 9000 | C | | 69 | 谢莹 | 2018-12-10 | 13369 | 4000 | C | | 74 | 赵成 | 2018-12-10 | 12154 | 8000 | C | | 84 | 朱文 | 2018-12-10 | 10938 | 7000 | C | | 96 | 胡瑜 | 2018-12-10 | 14585 | 11000 | C | | 100 | 马涛 | 2018-12-10 | 14585 | 11000 | C | | 126 | 谢琴 | 2018-12-10 | 10938 | 11000 | C | | 132 | 刘倩 | 2018-12-10 | 10938 | 11000 | C | | 50 | 臧龙 | 2018-12-10 | 10938 | 6000 | C | | 58 | 张伟 | 2018-12-10 | 13369 | 11000 | C | | 70 | 傅雪 | 2018-12-10 | 12154 | 3000 | C | | 115 | 陈建军 | 2018-12-10 | 13369 | 7000 | C | | 1 | 梁伟 | 2018-12-10 | 17016 | 7000 | D | | 5 | 郑静 | 2018-12-10 | 17016 | 3000 | D | | 13 | 王楠 | 2018-12-10 | 18231 | 3000 | D | | 17 | 陈阳 | 2018-12-10 | 19448 | 7000 | D | | 28 | 郑秀珍 | 2018-12-10 | 17016 | 9000 | D | | 32 | 冯建国 | 2018-12-10 | 18231 | 11000 | D | | 63 | 王玉华 | 2018-12-10 | 15800 | 8000 | D | | 98 | 李莹 | 2018-12-10 | 19448 | 9000 | D | | 108 | 宋艳 | 2018-12-10 | 18231 | 2000 | D | | 6 | 牛建军 | 2018-12-10 | 17016 | 1000 | D | | 52 | 张冬梅 | 2018-12-10 | 19448 | 9000 | D | | 73 | 王璐 | 2018-12-10 | 17016 | 10000 | D | | 95 | 毛丹 | 2018-12-10 | 19448 | 8000 | D | | 99 | 王畅 | 2018-12-10 | 15800 | 5000 | D | | 125 | 李静 | 2018-12-10 | 17016 | 5000 | D | | 11 | 郭兰英 | 2018-12-10 | 17016 | 8000 | D | | 20 | 蒋红 | 2018-12-10 | 19448 | 3000 | D | | 49 | 李平 | 2018-12-10 | 15800 | 9000 | D | | 79 | 叶欣 | 2018-12-10 | 15800 | 4000 | D | | 92 | 陶红 | 2018-12-10 | 19448 | 2000 | D | | 110 | 萧秀华 | 2018-12-10 | 18231 | 2000 | D | | 4 | 张健 | 2018-12-10 | 17016 | 2000 | D | | 12 | 王英 | 2018-12-10 | 15800 | 4000 | D | | 21 | 曹宁 | 2018-12-10 | 18231 | 11000 | D | | 46 | 罗建华 | 2018-12-10 | 15800 | 7000 | D | | 62 | 林刚 | 2018-12-10 | 15800 | 4000 | D | | 66 | 罗岩 | 2018-12-10 | 19448 | 7000 | D | | 81 | 徐成 | 2018-12-10 | 17016 | 3000 | D | | 85 | 刘玲 | 2018-12-10 | 15800 | 1000 | D | | 107 | 游静 | 2018-12-10 | 18231 | 7000 | D | | 123 | 许欣 | 2018-12-10 | 19448 | 10000 | D | | 127 | 李瑞 | 2018-12-10 | 17016 | 6000 | D | | 38 | 曹凯 | 2018-12-10 | 23093 | 3000 | E | | 86 | 张宇 | 2018-12-10 | 24309 | 4000 | E | | 102 | 张亮 | 2018-12-10 | 23093 | 3000 | E | | 112 | 田兰英 | 2018-12-10 | 24309 | 9000 | E | | 2 | 郭岩 | 2018-12-10 | 20662 | 9000 | E | | 10 | 郭娟 | 2018-12-10 | 21878 | 8000 | E | | 25 | 邵佳 | 2018-12-10 | 23093 | 3000 | E | | 29 | 胡秀云 | 2018-12-10 | 23093 | 1000 | E | | 33 | 曹杰 | 2018-12-10 | 23093 | 6000 | E | | 48 | 范秀英 | 2018-12-10 | 25524 | 1000 | E | | 56 | 陈洁 | 2018-12-10 | 23093 | 3000 | E | | 68 | 柴冬梅 | 2018-12-10 | 25524 | 9000 | E | | 91 | 李建华 | 2018-12-10 | 20662 | 11000 | E | | 105 | 王小红 | 2018-12-10 | 21878 | 8000 | E | | 117 | 和林 | 2018-12-10 | 25524 | 11000 | E | | 7 | 刘斌 | 2018-12-10 | 23093 | 4000 | E | | 34 | 苗桂花 | 2018-12-10 | 23093 | 1000 | E | | 40 | 王淑珍 | 2018-12-10 | 20662 | 2000 | E | | 53 | 邢成 | 2018-12-10 | 25524 | 8000 | E | | 57 | 许辉 | 2018-12-10 | 23093 | 3000 | E | | 61 | 沈秀梅 | 2018-12-10 | 24309 | 3000 | E | | 88 | 田英 | 2018-12-10 | 20662 | 2000 | E | | 106 | 苏波 | 2018-12-10 | 23093 | 5000 | E | | 118 | 宋慧 | 2018-12-10 | 23093 | 3000 | E | | 122 | 区军 | 2018-12-10 | 21878 | 2000 | E | | 8 | 汪云 | 2018-12-10 | 23093 | 2000 | E | | 16 | 聂想 | 2018-12-10 | 21878 | 8000 | E | | 27 | 梁勇 | 2018-12-10 | 24309 | 5000 | E | | 31 | 刘海燕 | 2018-12-10 | 25524 | 9000 | E | | 37 | 朱淑兰 | 2018-12-10 | 24309 | 4000 | E | | 54 | 孙丹 | 2018-12-10 | 21878 | 9000 | E | | 76 | 刘桂兰 | 2018-12-10 | 20662 | 11000 | E | | 119 | 张梅 | 2018-12-10 | 23093 | 10000 | E | +-------------+-----------+------------+-------+-------+-------+ 120 rows in set (0.01 sec)
查询生日与入职月份相同的员工 mysql> select -> e.name,e.birth_date,em.hire_date -> from employees as e -> inner join employees as em -> on month(e.birth_date)=month(em.hire_date) -> and e.employee_id=em.employee_id; +-----------+------------+------------+ | name | birth_date | hire_date | +-----------+------------+------------+ | 李玉英 | 1974-01-25 | 2012-01-19 | | 郑静 | 1997-02-14 | 2018-02-03 | | 林刚 | 1990-09-23 | 2007-09-19 | | 刘桂兰 | 1982-10-11 | 2003-10-14 | | 张亮 | 1996-08-25 | 2015-08-10 | | 许欣 | 1982-09-25 | 2011-09-09 | | 王荣 | 1999-11-22 | 2019-11-14 | +-----------+------------+------------+ 7 rows in set (0.00 sec)
外连接 left join左连接,左边是主表 mysql> select -> d.dept_id,dept_name,name -> from departments as d -> left outer join employees as e -> on d.dept_id=e.dept_id; +---------+-----------+-----------+ | dept_id | dept_name | name | +---------+-----------+-----------+ | 1 | 人事部 | 梁伟 | 。。。。。。。。。。。 | 8 | 法务部 | 杨金凤 | | 9 | NULL | NULL | +---------+-----------+-----------+ 134 rows in set (0.00 sec)right join右连接,右边是主表 mysql> select d.dept_id,dept_name,name -> from departments as d -> right outer join employees as e -> on d.dept_id=e.dept_id; +---------+-----------+-----------+ | dept_id | dept_name | name | +---------+-----------+-----------+ | 1 | 人事部 | 梁伟 | 。。。。。。。。。。。 | 8 | 法务部 | 杨金凤 | +---------+-----------+-----------+ 133 rows in set (0.00 sec)
子查询 select之后:仅支持单行单列 from之后:支持多行多列 where或having之后:支持单行单列、单行多列、多行单列
查询运维部所有员工信息 mysql> select *from employees where dept_id=( select dept_id from departments where dept_name='运维部'); +-------------+-----------+------------+------------+--------------------+--------------+---------+ | employee_id | name | hire_date | birth_date | email | phone_number | dept_id | +-------------+-----------+------------+------------+--------------------+--------------+---------+ | 14 | 廖娜 | 2012-05-20 | 1982-06-22 | liaona@tarena.com | 15827928192 | 3 | | 15 | 窦红梅 | 2018-03-16 | 1971-09-09 | douhongmei@tedu.cn | 15004739483 | 3 | | 16 | 聂想 | 2018-09-09 | 1999-06-05 | niexiang@tedu.cn | 15501892446 | 3 | | 17 | 陈阳 | 2004-09-16 | 1991-04-10 | chenyang@tedu.cn | 15565662056 | 3 | | 18 | 戴璐 | 2001-11-30 | 1975-05-16 | dailu@tedu.cn | 13465236095 | 3 | | 19 | 陈斌 | 2019-07-04 | 2000-01-22 | chenbin@tarena.com | 13621656037 | 3 | +-------------+-----------+------------+------------+--------------------+--------------+---------+ 6 rows in set (0.00 sec) 查询2018年比100号员工工资高的工资信息 mysql> select *from salary -> where year(date)=2018 and month(date)=12 and basic>(select basic from salary where year(date)=2018 and month(date)=12 and employee_id=100); 查询比开发部人数少的部门 1,查询开发部编号 select dept_id from departments where dept_name='开发部'; 2,查询开发部人数 select count(*) from employees where dept_id=4; 3,查询各部门人数 select dept_id,count(*) from employees group by dept_id; 4,查询人数比55 少的部门 select dept_id,count(*) from employees group by dept_id having count(*)<55;
select dept_id,count(*) from employees group by dept_id having count(*)<( select count(*) from employees where dept_id=4 ( select dept_id from departments where dept_name='开发部' ) );
查询每个部门人数 mysql> select d.*,(select count(*) from employees as e where d.dept_id=e.dept_id) as amount from departments as d; +---------+-----------+--------+ | dept_id | dept_name | amount | +---------+-----------+--------+ | 1 | 人事部 | 8 | | 2 | 财务部 | 5 | | 3 | 运维部 | 6 | | 4 | 开发部 | 55 | | 5 | 测试部 | 12 | | 6 | 市场部 | 9 | | 7 | 销售部 | 35 | | 8 | 法务部 | 3 | | 9 | NULL | 0 | +---------+-----------+--------+ 9 rows in set (0.00 sec)分页查询LIMIT mysql> select employee_id,name from employees -> order by employee_id -> limit 0,5; +-------------+-----------+ | employee_id | name | +-------------+-----------+ | 1 | 梁伟 | | 2 | 郭岩 | | 3 | 李玉英 | | 4 | 张健 | | 5 | 郑静 | +-------------+-----------+ 5 rows in set (0.00 sec) mysql> select employee_id,name from employees order by employee_id limit 5,5; +-------------+-----------+ | employee_id | name | +-------------+-----------+ | 6 | 牛建军 | | 7 | 刘斌 | | 8 | 汪云 | | 9 | 张建平 | | 10 | 郭娟 | +-------------+-----------+ 5 rows in set (0.00 sec)联合查询UNION mysql> ( -> select name, birth_date from employees -> where year(birth_date)<1972 -> ) -> union -> ( -> select name, birth_date from employees -> where year(birth_date)>2000 -> ); +-----------+------------+ | name | birth_date | +-----------+------------+ | 梁伟 | 1971-08-19 | | 张建平 | 1971-11-02 | | 窦红梅 | 1971-09-09 | | 温兰英 | 1971-08-14 | | 朱文 | 1971-08-15 | | 和林 | 1971-12-10 | +-----------+------------+ 6 rows in set (0.00 sec)