- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有两个包含多行的表。第一个称为 comments
并具有以下结构:
user_id last_commented
........................
9239289 2017-11-06
4239245 2017-11-05
4239245 2017-11-03
6239223 2017-11-02
1123139 2017-11-04
第二个称为users
,具有以下结构:
user_id user_name user_status
.................................
9239289 First Name 0
4239245 First Name2 2
6239223 First Name3 1
1123139 First Name4 2
我需要一个查询来显示过去 3 天未添加评论的用户,user_status
等于 2 并显示自他们上次评论以来的天数。
到目前为止,这是我的查询:
select u.*
from users u
where not exists (
select 1
from comments c
where c.user_id = u.user_id and last_commented > DATE(NOW()) - INTERVAL 3 DAY
) and user_status = 2
正确输出过去 3 天未发表评论的用户。我如何修改它以显示自他们上次评论以来的天数?
最佳答案
如果您需要自上次评论以来的天数,那么您将需要某种join
:
select u.*, datediff(curdate(), last_commented)
from users u left join
comments c
on c.user_id = u.user_id
where u.status = 2
group by u.user_id
having max(last_commented) < curdate() - interval 3 day or
max(last_commented) is null;
此版本包括完全未发表评论的用户。
关于mysql - 显示自用户上次评论以来的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47136619/
之前看到一些类似的问题,想弄清楚。 在this article ,据说异步调用“没有线程”。 然而,in another one ,据说 Here, however, we’re running th
我为我公司的平板电脑(SAMSUNG Galaxy Tab Active2)开发了一个简单的软件,自上周五(2018 年 11 月 23 日)以来,它无法正常工作。我检查了该应用程序的所有功能,其中有
我正在使用 hadoop map-reduce 作业进行一些文本处理。我的工作已完成 99.2%,并停留在上一个 map 工作上。 map 输出的最后几行如下所示。上次发生此问题时,我尝试打印出从 m
上次 Ubuntu 更新后有人对 Docker 有疑问吗?我有 2 个由 docker-compose 在 ubuntu18.04 中运行的项目。两个项目都运行良好,但在 *.yml 中进行 0 次更
SQL Developer 在表中显示公共(public)同义词的创建和上次 DDL 时间: CREATED 15-AUG-09 LAST_DDL_TIME 15-AUG-09 O
我正在使用带有以下插件的 mavenized 库项目: com.jayway.maven.plugins.android.generation2
我正在使用 Jssor Slider 作为轮播。在 Google Chrome 上次更新到版本 45.0.2454.85 之前,它一直运行良好。想法是它不显示图像。目前,它们位于标签中,可在 Safa
我是一名优秀的程序员,十分优秀!