postgresql 查找一年之内是否存在充值记录的sql

x33g5p2x  于2021-11-19 转载在 其他  
字(0.8k)|赞(0)|评价(0)|浏览(380)

查找一年之内的数据库的记录,sql的写法

select * from sub_account_record where operate_type='INCOME'  and transaction_type='ONLINE_RECHARGE' and transaction_time  >( now()-interval '1 year')

spring boot jpa 的代码的中的写法

override fun isCashAccount(tenantId: Long): Boolean {
		val queryWrapper: QueryWrapper<SubAccountRecord> = QueryWrapper<SubAccountRecord>()
		queryWrapper.allEq(mapOf("tenant_id" to tenantId, "transaction_type" to TransactionType.ONLINE_RECHARGE, "operate_type" to OperateType.INCOME))
		queryWrapper.ge("transaction_time",LocalDateTime.now().minusYears(1L))
		return subAccountRecordDao.selectCount(queryWrapper)>0
	}

jpa打印出来的sql日志为

SELECT COUNT( * ) FROM sub_account_record WHERE deleted=0 AND (tenant_id = 1453580696349184000 AND transaction_type = 'ONLINE_RECHARGE' AND operate_type = 'INCOME' AND transaction_time >= '2020-11-19T15:47:17.784938900')

相关文章