Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 过去12个月之间的交易时间_Sql - Fatal编程技术网

Sql 过去12个月之间的交易时间

Sql 过去12个月之间的交易时间,sql,Sql,我需要的结果,从过去12个月之间的交易时间从今天的交易。示例2018-10-1至2019-09-30。在该日期进行交易的人员。但是结果返回为空 select CMM.membership_id, person_birthdayMonth, transaction_time from cognetic_core_person where transaction_time = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) and DATEA

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

select  CMM.membership_id, person_birthdayMonth, transaction_time
from cognetic_core_person
where 
transaction_time = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0) and DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-12, 0) >= transaction_time and DATENAME(month,GETDATE()) = CCP.person_birthdayMonth
我想你想要:

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;
选择CMM.membership\u id、person\u birthdayMonth、transaction\u time
来自认知核心人物
其中,事务处理时间>=DATEFROMPARTS(年(GETDATE())-1、月(GETDATE())、1)和
事务处理时间
用您正在使用的数据库标记您的问题。