最近12个月之间的交易时间

时间:2019-10-29 15:28:22

标签: sql

我需要从今天起的过去12个月之间的交易时间得出的结果。例如2018-10-1至2019-09-30。在此日期之间进行交易的人。但是结果返回为空。

+----+------------+---------+------+----------+---+
| ID |    Date    |  Limit  | Plan | Category |   |  
+----+------------+---------+------+----------+---+
|  1 | 20-11-2018 |  67000  |  CP  |    B     | X |  
|  2 | 08-08-2019 |  32000  |  CO  |    C     | ✓ |  
|  3 | 05-03-2019 |  12000  |  CO  |    A     | ✓ |  
|  4 | 18-10-2019 |  70000  |  CP  |    B     | ✓ |
|  5 | 16-04-2019 |  52000  |  CO  |    B     | X |
|  6 | 23-07-2018 |  17000  |  CP  |    A     | ✓ |     
+----+------------+---------+------+----------+---+

1 个答案:

答案 0 :(得分:0)

我想你想要

select CMM.membership_id, person_birthdayMonth, transaction_time
from cognetic_core_person
where transaction_time >= DATEFROMPARTS(YEAR(GETDATE()) - 1, MONTH(GETDATE()), 1) AND
      transaction_time < DATEFROMPARTS(YEAR(GETDATE()), MONTH(GETDATE()), 1) AND
      DATENAME(month, GETDATE()) = CCP.person_birthdayMonth;