| 100001 | 红枫 | 29 | 9000 | 1977-01-01 | male |
| 100002 | 丽鹃 | 27 | 8000 | 1979-12-31 | fmale |
+--------+----------+---------+---------+------------+---------+
3 rows in set (0.00 sec)
----------------------我------------割--------------------------
2.6 高级查询方法
2.6.1 记录查询
查询emp表中,emp_name为啸天的全部信息
mysql> select * from emp where emp_name='啸天';
查询结果显示如下:
+--------+----------+---------+---------+------------+---------+
| emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex |
+--------+----------+---------+---------+------------+---------+
| 100005 | 啸天 | 27 | 4000 | 1979-07-10 | male |
+--------+----------+---------+---------+------------+---------+
1 row in set (0.00 sec)
查询emp表中,emp_sal,工资在5000以上的全部信息
mysql> select * from emp where emp_sal>5000;
查询结果显示如下:
+--------+----------+---------+---------+------------+---------+
| emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex |
+--------+----------+---------+---------+------------+---------+
| 100001 | 红枫 | 29 | 9000 | 1977-01-01 | male |
| 100002 | 丽鹃 | 27 | 8000 | 1979-12-31 | fmale |
+--------+----------+---------+---------+------------+---------+
2 rows in set (0.00 sec)
查询emp表中在1978年1月1日之后出生的
mysql> select * from emp where emp_bir>'1978-01-01';
查询结果显示如下:
+--------+----------+---------+---------+------------+---------+
| emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex |
+--------+----------+---------+---------+------------+---------+
| 100005 | 啸天 | 27 | 4000 | 1979-07-10 | male |
| 100002 | 丽鹃 | 27 | 8000 | 1979-12-31 | fmale |
+--------+----------+---------+---------+------------+---------+
2 rows in set (0.00 sec)
查询emp表中在1979年12月1日之前出生,工资在5000以上的
mysql> select * from emp where emp_bir<'1979-12-01' and emp_sal>5000;
查询结果显示如下:
+--------+----------+---------+---------+------------+---------+
| emp_id | emp_name | emp_age | emp_sal | emp_bir | emp_sex |
+--------+----------+---------+---------+------------+---------+
| 100001 | 红枫 | 29 | 9000 | 1977-01-01 | male |
+--------+----------+---------+---------+------------+---------+
1 row in set (0.00 sec)
2.6.2 字段查询
CEO查看员工工资情况
mysql> select emp_name,emp_sal from emp;
查询结果显示如下:
+----------+---------+
| emp_name | emp_sal |
+----------+---------+
| 啸天 | 4000 |
| 红枫 | 9000 |
| 丽鹃 | 8000 |
+----------+---------+
3 rows in set (0.00 sec)
查看1978年后出生的人的姓名、工资和性别
mysql> select emp_name,emp_sal,emp_sex from emp where emp_bir>"1977-12-31";
查询结果显示如下:
+----------+---------+---------+
| emp_name | emp_sal | emp_sex |
+----------+---------+---------+
| 啸天 | 4000 | male |
| 丽鹃 | 8000 | fmale |
+----------+---------+---------+
2 rows in set (0.00 sec)
2.6.3 查询结果排序
用ORDER BY语句对emp表中所有员工工资高低顺序查询结果(默认是从低到高——升序)
mysql> select * from emp order by emp_sal;
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一篇:
MySQL 5 on Linux手动安装方法 下一篇:
MySQL将为数据库管理员减负
【文章评论】
【收藏本文】
【推荐好友】
【打印本文】
【我要投稿】 【论坛讨论】