不显示日期期间
Doesn't displaying date period
我在过滤日期时遇到问题。我有 SQL-查询,它在特定日期显示所有必需的参数。我认为我还需要创建查询,它将 return 相同的参数,但需要几个日期。
示例:现在在我的查询“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
关键字来引入文字日期。
我在过滤日期时遇到问题。我有 SQL-查询,它在特定日期显示所有必需的参数。我认为我还需要创建查询,它将 return 相同的参数,但需要几个日期。
示例:现在在我的查询“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
关键字来引入文字日期。