MySQL 视图中上次查询以来的新记录 [英] New records since last query in MySQL View

查看:46
本文介绍了MySQL 视图中上次查询以来的新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种创建视图的方法,该视图在查询时将自动仅检索自上次查询以来的新记录.我的表的所有条目都有一个时间戳字段,所以对于一个简单的例子,我可以

I am looking for a way to create a View that when queried will automatically only retrieve new records since the last query. My tables have a timestamp field for all entries, so for a simple example I can

SELECT * WHERE timestamp >= 'blah'

但我不知道如何从上次查询中确定 blah 应该是什么.因此,如果在 11:00 查询视图,然后在 12:00 再次查询,则 12:00 的查询应仅返回自 11:00 以来添加的记录.等等......这一切都需要在View中完成,最终用户应该能够简单地查询View并获得结果.

but I don't know how to determine what blah should be from the last query. So if the View was queried at 11:00 and then again at 12:00, the query at 12:00 should only return records added since 11:00. And so on... This all needs to be accomplished in the View, the end user should simply be able to query the View and get the results.

这可能吗?

推荐答案

有两种方式:

  1. 在每个用户持久会话的数据库中存储上次访问日期时间桌子,如果你有的话.在对数据库的下一次视图调用时,使用会话中的上一次最近访问时间以过滤开始的行来自.

  1. Store last access date time in database per user persistent session table, if you have one. On next view call to database, use the previous latest access time in the session to filter rows starting from.

在客户端的用户虚拟会话中存储上次访问日期时间环境.在每次调用服务器时,将上次访问日期时间发送为出色地.以便服务器使用它来过滤从以下位置开始的行.

Store last access date time in user virtual session at client environment. On every call to server, send last access date time as well. So that server uses it to filter rows starting from.

我更喜欢使用第二个选项,即进程不会在数据库表中写入任何数据.

I prefer to use second option that process won't write any data in database tables.

这篇关于MySQL 视图中上次查询以来的新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆