我必须在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/