#sql 请问怎么并列查询 或者 怎么讲两条语句查询的结果拼接起来?
问题描述:
sql 初学者;
遇到了一个基础的sql语句练习题
原题:
Show year, subject, and name of people who won a 'Medicine' prize in an early year (before 1910, not including 1910) together with winners of a 'Literature' prize in a later year (after 2004, including 2004) 要查出1910年以前的诺贝尔医学奖的获奖者名单以及2004年以后的诺贝尔文学奖获奖者名单,要求在一起显示
表的名字叫nobel
表有三列,yr 年份, subject 奖项类别, winner获奖者姓名
想知道怎么用一条sql语句实现?
我原本的接替思路是用两条select 语句实现然后用union拼接起来,发现也做不到。
这是我写的,但是逻辑上不通
SELECT * FROM nobel
WHERE subject = 'Medicine' AND yr < 1910
OR
subject = 'Literature' AND yr >= 2004;
答
SELECT * FROM nobel
WHERE subject = 'Medicine' AND yr < 1910输出是有数值吗?
答
SELECT * FROM nobel
WHERE
(subject = 'Medicine' AND yr < 1910)
and
(subject = 'Literature' AND yr >= 2004);