我正在用 SQL 编写一个创建视图程序,而我的最后一个创建视图语句给我带来了一些麻烦。对于这个观点声明,我想从哥伦比亚市的所有大学中检索所有 uid。然后我想使用一个子查询来获取这个人的名字和姓氏的信息。官方描述如下
Write a query that returns only the uid value for all universities in the city Columbia. Then use
that query with an IN sub-query expression to retrieve the first and last names for all people that
go to school in Columbias
我现在将发布我为 create table 语句编写的代码,然后我将发布我将用于 view 语句的两个表。我在这里先向您的帮助表示感谢。
CREATE VIEW inn AS
SELECT a.uid
FROM letsdoit.university as a
WHERE b.fname, b.lname IN(SELECT b.fname, b.lname FROM letsdoit.person as b WHERE (a.city = "Columbia"));
这些表是
Table "letsdoit.university"
Column | Type | Modifiers
-----------------+-----------------------+--------------------------------------
uid | integer | not null default nextval('university) uid_seq'::regclass)
university_name | character varying(50) |
city | character varying(50) |
Table "letsdoit.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