gpt4 book ai didi

php - 根据操作向查询结果添加列

转载 作者:行者123 更新时间:2023-11-30 00:00:42 24 4
gpt4 key购买 nike

我们正在尝试实现增量同步。

我们有一个表OBJECTS,如下所示:

ID | ACTIVE | CREATED | MODIFIED | CONTENT
1 1 1234 1235 text

客户端向服务器发送他的最后同步日期(一个长整数)。

[S = LastSync; C = created; M = Modified]

查询仅选择带有 M>S 的行。

当需要新列ACTION时,可以是0(插入)、1(更新)或2(删除)[用于告诉客户要做什么]。

ACTION 将遵循以下规则:

if(C==M && S<M) return 0; //Object created, not modified, last sync before creation

if(C<M && C<S<M && ACTIVE == 1) return 1; //Object modified, still active, sync between creation and modification

if(C<M && C<S<M && ACTIVE == 0) return 2; //Object modified, not active, sync between creation and modification

if(C<M && S<C) return 0; //Object modified, last sync before creation

有没有办法通过 MySQL 中的查询来完成这一切?

最佳答案

我已经为您的“4-if 条件”创建了一个 SQL 查询逻辑(仅限)...尝试一下它是否适合您:

select ((created<modified) + (created<LastSync) + (LastSync<modified) -
((active or LastSync<created) and (created<Modified)) - 1) as action;

关于php - 根据操作向查询结果添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25057638/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com