问题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 面试题’对您有任何帮助吗?别忘了在下面留言,写出您的宝贵意见。