我有一张表格,其中以以下格式存储了两个日期:例如2014-12-05。这些日期是日期和日期。我想从另一个有日期列的表中选择项目。因此,我想执行以下操作:
SELECT * FROM TABLE2 WHERE date BETWEEN fromdate AND todate
除了fromdate和todate列来自table1,而'date'来自table2。有一个简洁的方法吗?
您将在两个表之间进行某种联接,然后从联接中选择条目。通过用逗号分隔要查询的表,可以实现简单的笛卡尔联接。
create table holidays (
name text not null,
fromdate text not null,
todate text not null
);
create table appointments (
name text not null,
date text not null
);
insert into holidays values ('Christmas Holiday', '2014-12-05', '2014-12-24');
insert into appointments values ('Dentist', '2014-11-06');
insert into appointments values ('Doctor', '2014-12-06');
select h.name, a.name, a.date
from appointments a, holidays h
where a.date between h.fromdate and h.todate;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句