0

我正在用 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
4

1 回答 1

0

根据问题陈述,您被指示创建的第一个查询应该是 IN 的子查询,并且应该用作查找该大学人员的名字和姓氏的标准(因为 UID 在两个 PERSON和大学),所以你的观点是这样的:

create view inn as
select fname, lname
  from letsdoit.person
 where uid in (select uid from letsdoit.university where city = 'Columbia')
于 2014-10-05T13:46:05.987 回答