我正试图找到一种可以列出迈阿密学生考试的方法。首先是表格和数据集。这是用户表:
CREATE TABLE users(
uno NUMBER(5),
email VARCHAR2(64),
password VARCHAR2(64),
fname VARCHAR2 (64) NOT NULL,
lname VARCHAR2 (64) NOT NULL,
address1 VARCHAR2 (64),
address2 VARCHAR2(64),
city VARCHAR2(64),
state VARCHAR2(64),
zip NUMBER(5),
CONSTRAINT users_pk PRIMARY KEY(uno));
用户数据集:
(1,'1@gmail.com','','Mike','Goose','','','Miami','FL','32323')
(2,'2@gmail.com','','Cathy','Vincent','','','Atlanta','GA','91901')
(3,'3@gmail.com','','Steve','McGarth','','','Miami','FL','345321')
userResponse表:
CREATE TABLE userResponse(
uno NUMBER (5),
eno NUMBER (5),
qno NUMBER(5),
response CHAR (1),
CONSTRAINT userResponse_pk PRIMARY KEY(uno, eno, qno),
FOREIGN KEY(uno, eno) REFERENCES enrolls(uno, eno),
FOREIGN KEY(eno, qno) REFERENCES question(eno, qno)
);
userResponse数据集:
(1,1,1,'A')
(1,1,2,'B')
(1,1,3,'A')
(1,1,4,'B')
(1,1,5,'N')
(1,1,6,'C')
(1,1,7,'D')
(1,1,8,'A')
(2,1,1,'B')
(2,1,2,'B')
(2,1,3,'E')
(2,1,4,'C')
(2,1,5,'D')
(2,1,6,'A')
(2,1,7,'C')
(2,1,8,'B')
(3,1,1,'C')
(3,1,2,'C')
(3,1,3,'D')
(3,1,4,'D')
(3,1,5,'A')
(3,1,6,'A')
我知道“uno”必须与“城市”(对于那些住在迈阿密的人)有某种关系。我有点被困在这里,因为我不知道如何一起检索两张桌子。如何从user表(城市)中检索列信息到userResponse表(uno)中的列,如何列出所有列信息?请告诉我。感谢。
EDIT1: 我在这里弄错了。这实际上是学生们参加的所有考试。我为此道歉。
答案 0 :(得分:4)
试试这个:
1)如果您想要所有的回复信息
SELECT *
FROM userResponses
WHERE uno IN
(
SELECT uno
FROM user
WHERE city = 'MIAMI'
)
2)如果你只想要考试号:
SELECT DISTINCT eno
FROM userResponses
WHERE uno IN
(
SELECT uno
FROM user
WHERE city = 'MIAMI'
)