我有过滤日期的问题。我有SQL查询,该查询在特定日期显示所有必需的参数。我认为我还需要创建查询,该查询将返回相同的参数,但有多个必需的日期。
示例:现在在我的查询“ 2020-12-06”,“ 2021-12-06”中。但是我想获取期间“ 2020-12-06”-“ 2021-12-06”的所有数据,我尝试创建一些内容,但最好的是-显示设置的日期,但不显示期间:
select ledgeraccounttypeid, dateeffective, sum(amount) from ledgertransaction
where ledgeraccounttypeid in (2,1,16) and dateeffective in('2020-12-06', '2021-12-06')
group by ledgeraccounttypeid, dateeffective
*重要提示:期间将根据程序设置
**我将拥有:“ YYYY.MM.DD”或“ YYYY.MM.DD-YYYY.MM.DD”。
你想between
?
where dateeffective between date '2020-12-06' and date '2021-12-06'
假定它dateeffective
是应具有的类似日期的数据类型。
在许多情况下,半开放时间间隔更适合需求:
where
dateeffective >= date '2020-12-06'
and dateeffective < date '2021-12-06' + interval '1' day
这种语法在Postgrs和MySQL中均适用,在后者中,我们将分配date
关键字以引入文字日期。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句