我有一张如下表格
CREATE TABLE student_marks (Name, Subject, Marks ) AS
SELECT 'Mike', 'Physics', 20 FROM DUAL UNION ALL
SELECT 'Mike', 'Bio', 20 FROM DUAL UNION ALL
SELECT 'Mike', 'Chemistry', 30 FROM DUAL UNION ALL
SELECT 'Ryan', 'Physics', 24 FROM DUAL UNION ALL
SELECT 'Ryan', 'Bio', 24 FROM DUAL UNION ALL
SELECT 'Ryan', 'Chemistry', 24 FROM DUAL;
我想得到Mike的物理学和Ryan的所有科目的名称和标记。我想要使用的查询是这样的
select *
from student_marks
where (Name,Subject) in (('Mike','Physics'),('Ryan',*));
我应该在查询中替换*以便它匹配Ryan的所有主题?
答案 0 :(得分:3)
将*
替换为Subject
:
Oracle 11g R2架构设置:
CREATE TABLE student_marks (Name, Subject, Marks ) AS
SELECT 'Mike', 'Physics', 20 FROM DUAL UNION ALL
SELECT 'Mike', 'Bio', 20 FROM DUAL UNION ALL
SELECT 'Mike', 'Chemistry', 30 FROM DUAL UNION ALL
SELECT 'Ryan', 'Physics', 24 FROM DUAL UNION ALL
SELECT 'Ryan', 'Bio', 24 FROM DUAL UNION ALL
SELECT 'Ryan', 'Chemistry', 24 FROM DUAL;
查询1 :
select *
from student_marks
where (Name,Subject) in (('Mike','Physics'),('Ryan',Subject))
<强> Results 强>:
| NAME | SUBJECT | MARKS |
|------|-----------|-------|
| Mike | Physics | 20 |
| Ryan | Physics | 24 |
| Ryan | Bio | 24 |
| Ryan | Chemistry | 24 |