Select 按 datediff 过滤查询
Select query filtering by datediff
我正在尝试编写一个查询,其中我按日期和年龄进行过滤,查询类似于
select *
from table1
where birthdate >= 'date1'
and dead <= 'date2'
where age >17
and <55;
table列是这样的
ID---name---lastname---birthdate---deadDate
您的查询非常接近。但是,任何时候您想要在 WHERE 子句中使用多个条件,您只需在每个条件之间使用 AND(或 OR)。试试这个:
SELECT *
FROM myTable
WHERE birthdate >= 'date1' AND death <= 'date2' AND age > 17 AND age < 55;
试试这个代码
select * from table1 where birthdate BETWEEN 'date1' and 'date2 and age > 17 and age < 55
BETWEEN 函数会将生日字段与包含在范围内的日期进行比较。
PD:我强烈建议在发布问题之前多做一些努力和研究。
select * from table1
where birthdate >= 'date1'
and deadDate <= 'date2'
and DATEDIFF(birthdate,deadDate) between > 17 and < 55;
我正在尝试编写一个查询,其中我按日期和年龄进行过滤,查询类似于
select *
from table1
where birthdate >= 'date1'
and dead <= 'date2'
where age >17
and <55;
table列是这样的
ID---name---lastname---birthdate---deadDate
您的查询非常接近。但是,任何时候您想要在 WHERE 子句中使用多个条件,您只需在每个条件之间使用 AND(或 OR)。试试这个:
SELECT *
FROM myTable
WHERE birthdate >= 'date1' AND death <= 'date2' AND age > 17 AND age < 55;
试试这个代码
select * from table1 where birthdate BETWEEN 'date1' and 'date2 and age > 17 and age < 55
BETWEEN 函数会将生日字段与包含在范围内的日期进行比较。
PD:我强烈建议在发布问题之前多做一些努力和研究。
select * from table1
where birthdate >= 'date1'
and deadDate <= 'date2'
and DATEDIFF(birthdate,deadDate) between > 17 and < 55;