Sql 过去12个月之间的交易时间
我需要的结果,从过去12个月之间的交易时间从今天的交易。示例2018-10-1至2019-09-30。在该日期进行交易的人员。但是结果返回为空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
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)和
事务处理时间
用您正在使用的数据库标记您的问题。