首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何跟踪实时点的变化?

如何跟踪实时点的变化?
EN

Stack Overflow用户
提问于 2016-01-02 16:42:27
回答 1查看 125关注 0票数 0

我正在做一个会员系统,允许会员赚取和使用积分。其中一些积分也有有效期。

目前我的系统有3个数据库表。

1)包含个人详细信息的成员表,并有一列用于存储成员的总积分。

2)用于存储积分收入和到期日期(如果有)的交易表

3)积分使用表,用于存储使用了多少积分的记录,可能用于从我的网站购买商品(每行每次使用)

我很难确定哪些积分在过期之前正在使用,或者它只是过期了。

所以我希望我能在这里得到一些建议或建议。或者是我的数据库表设计有什么问题导致了这个问题?

更新:一旦会员获得或使用积分,保持更新会员表中的总点数列是好的吗,这会使系统做额外的工作吗?

EN

回答 1

Stack Overflow用户

发布于 2016-01-02 18:35:45

我不确定我确切地理解你需要什么,但我想出了这样的东西:

代码语言:javascript
运行
复制
create table UserPoints(

    Id int not null identity( 1, 1 ),
    UserId int not null,
    Points int not null,
    [Date] datetime2( 3 ) not null,
    ExpireDate datetime2( 3 ) null

)
Go

-- + for earning points
-- - for loosing points
Insert into UserPoints Values
( 1,10,getdate(), null ),
( 1,10,dateadd(hour,1,getdate()), null ),
( 1,100,dateadd(month,2,getdate()), '2016-04-02' ),
( 1,-15,dateadd(month,3,getdate()), null ),
( 1,30,dateadd(month,4,getdate()), null )
Go


select * from UserPoints  order by [date]

--declare @checkDate datetime2(3) = '2016-04-02'
--declare @checkDate datetime2(3) = '2016-04-02 10:00'
declare @checkDate datetime2(3) = '2016-04-03'

select
    sum( points ) as 'UserPointsAtSpecificDate'
from
    UserPoints
where
    ( UserId = 1 )
    and ( [date] <= @checkDate )
    and ( isnull( expireDate, '9999-12-31' ) >= @checkDate )
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34564110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档