手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

15个 MySQL 基础面试题,DBA 们准备好了吗?

[日期:2014-01-06] 来源:Linux中国   作者:Linux [字体:大 中 小]

问题11:如何从表(比如 oc_users )中获取一个 field 对象(比如 uid)的所有数据?

答案:运行命令 select uid from oc_users;

MySQL> select uid from oc_users;
+-----+
| uid |
+-----+
| avi |
+-----+
1 row in set (0.03 sec)

问题12:假设你有一个名为 ‘xyz’ 的表,它存在多个字段,如 ‘createtime’ 和 ‘engine’。名为 engine 的字段由 ‘Memoty’ 和 ‘MyIsam’ 两种数值组成。如何只列出 ‘createtime’ 和 ‘engine’ 这两列并且 engine 的值为 ‘MyIsam’?

答案:运行命令 select create_time, engine from xyz where engine = ”MyIsam”;

mysql> select create_time, engine from xyz where engine="MyIsam";

+---------------------+--------+
| create_time        | engine |
+---------------------+--------+
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-12-15 13:43:27 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
| 2013-10-23 14:56:38 | MyISAM |
+---------------------+--------+
132 rows in set (0.29 sec)

问题13:如何列出表 ‘xrt’ 内 name 域值为 ‘linuxidc’,web_address 域值为 ‘linuxidc.com’ 的所有数据?

答案:运行命令 select * from xrt where name = “linuxidc” and web_address = “linuxidc.com”;

mysql> select  * from xrt where name = "linuxidc" and web_address = “linuxidc.com”;
+---------------+---------------------+---------------+
| Id                  | name                  | web_address |
+---------------+---------------------+----------------+
| 13                |  linuxidc              | linuxidc.com  |
+---------------+---------------------+----------------+
| 41                |  linuxidc              | linuxidc.com  |
+---------------+---------------------+----------------+

问题14:如何列出表 ‘xrt’ 内 name 域值不为 ‘linuxidc’,web_address 域值为 ‘linuxidc.com’ 的所有数据?

答案:运行命令 select * from xrt where name != "linuxidc" and web_address = "linuxidc.com";

mysql> select * from xrt where name != ”linuxidc” and web_address = ”linuxidc.com”;

+---------------+---------------------+---------------+
| Id            | name                | web_address  |
+---------------+---------------------+----------------+
| 1173          |  linuxidc            | linuxidc.com  |
+---------------+---------------------+----------------+

问题15:如何知道表内行数?

答案:运行命令 select count(*) from table_name;

mysql> select count(*) from Tables;

+----------+
| count(*) |
+----------+
|      282 |
+----------+
1 row in set (0.01 sec)

以上是文章的全部内容。这篇‘Linux 面试题’对您有任何帮助吗?别忘了在下面留言,写出您的宝贵意见。

linux
相关资讯       MySQL面试题 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款