22. 数据库查询(填空)

试题概述:

在系统 server0  上使用数据库 Contacts,并使用相应的 SQL 查询以回答下列问题:

 密码是 solicitous 的人的名字?

 有多少人的姓名是 Barbara 同时居住在 Sunnyvale?

解题参考:

mysql -u root -p

Enter password:

MariaDB [Contacts]> USE Contacts;

MariaDB [(none)]> show tables;   #查看数据库中的表

MariaDB [(none)]> desc base; 

MariaDB [(none)]> desc location; 

MariaDB [Contacts]> SELECT name FROM base WHERE password='solicitous'; 

+---------+ 

| name     | 

+---------+ 

| Barbara  | 

+---------+ 

1 row in set (0.00 sec) 

 

MariaDB [Contacts]> SELECT count(*) FROM base,location WHERE base.name='Barbara' AND 

location.city='Sunnyvale' AND base.id=location.id; 

+----------+ 

| count(*)   | 

+----------+ 

|              1 | 

+----------+ 

1 row in set (0.00 sec) 

MariaDB [Contacts]> QUIT

版权声明:
作者:WaterBear
链接:https://l-t.top/161.html
来源:雷霆运维
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>