SQLite查询返回一个空光标

时间:2017-04-10 21:53:16

标签: sqlite

此查询不返回任何内容。我怀疑问题是在WHERE行的某个地方,但我无法弄明白。任何帮助将非常感谢!

select companies.name, offers.salary, offers.bonus, offers.equity
from offers
join companies
    on companies.id = offers.company_id
join students
    on students.id = offers.student_id
where students.dob = (select max(dob) from students);

1 个答案:

答案 0 :(得分:0)

也许没有什么可以归还的 - 这取决于数据。尝试运行此脚本:

#!/bin/sh

sqlite3 <<EOS
create table companies(id integer primary key, name text);
create table students(id integer primary key, dob);
create table offers(salary,
                    bonus,
                    equity,
                    company_id references companies(id),
                    student_id references students(id));

insert into companies(id, name) values(1, 'Company X');
insert into companies(id, name) values(2, 'Company Y');

insert into students(id, dob) values(101, 19910101);
insert into students(id, dob) values(102, 19920202);
insert into students(id, dob) values(103, 19930303);

insert into offers(salary, bonus, equity, company_id, student_id)
            values('\$80K/yr', '\$6000', 'unknown', 1, 101);
insert into offers(salary, bonus, equity, company_id, student_id)
            values('\$70K/yr', '\$5000', 'unknown', 2, 102);
insert into offers(salary, bonus, equity, company_id, student_id)
            values('\$60K/yr', '\$4000', 'unknown', 2, 103);

select 'Companies:';
select * from companies;

select '';
select 'Offers:';
select * from offers;

select '';
select 'Students:';
select id, dob from students;

select '';
select '-----';
select companies.name, offers.salary, offers.bonus, offers.equity, dob
from offers
join companies
    on companies.id = offers.company_id
join students
    on students.id = offers.student_id
where students.dob = (select max(dob) from students);

EOS

最终选择应返回答案。现在删除商品表中的第三个插入。最终的选择不会像预期的那样返回任何内容。