mysql - 使用 EXIST 命令创建 sql View 语句

标签 mysql sql view create-view

我必须在sql中编写一条使用exist命令的create view语句。我尝试在网上查找,但遇到了一些困难。我尽力编写创建 View 文件,但它现在不起作用。我知道我需要在语句中使用关键字 EXIST。我试图创建的语句是

Write a query that shows returns the name and city of the university that has no people in database
that are associated with it.

到目前为止我写的代码是这样的

CREATE VIEW exist AS
SELECT a.university_name, a.city
FROM lab5.university as a
INNER JOIN lab5.person as b
ON a.uid = b.uid
WHERE b.uid  NOT EXIST

我正在使用的表是

         Table "table.university"
     Column      |         Type          |                        Modifiers     
-----------------+-----------------------+--------------------------------------
 uid             | integer               | not null default nextval('university_uid_seq'::regclass)
 university_name | character varying(50) | 
 city            | character varying(50) |

并且

            Table "table.person"
 Column |         Type          |                      Modifiers                       
--------+-----------------------+-----------------------------------------------
 pid    | integer               | not null default nextval('person_pid_seq'::reg class)
 uid    | integer               | 
 fname  | character varying(25) | not null
 lname  | character varying(25) | not null

最佳答案

您好,请使用以下代码并让我知道反馈

CREATE VIEW checkuni AS SELECT a.university_name, a.city FROM university as a WHERE NOT EXISTS (SELECT p.uid FROM person as p WHERE p.uid = a.uid)

关于mysql - 使用 EXIST 命令创建 sql View 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26199719/

相关文章:

sql - 将 .bacpac 从一个 Azure SQL Server 还原到另一个 Azure SQL Server 后,包含的用户密码和登录用户密码不起作用

mysql - 如何在MySQL中正确的GROUP BY?

android - 如何缩放 View 以适应 Android 动画中的内容大小?

java - 数据库 View 与选择查询?

asp.net-mvc - 在 ASP.NET MVC 中将 ID 放在 <body> 上

mysql - 对于 202 到 203 之间的每个 manager_id,显示每个经理监督的员工数量

javascript - 从两个变量计算任务的紧迫性

sql - 如何计算从现在开始的 'x'工作时间? (首选 sql 或 postgresql 9.3)

mysql - 合并来自同一来源的两个计数查询

MySQL 8 - DROP 或 ALTER 导致错误 3664 (HY000) : Failed to set SDI