gpt4 book ai didi

mysql - 根据日期获取记录(最近30天)

转载 作者:行者123 更新时间:2023-11-29 11:00:52 25 4
gpt4 key购买 nike

我正在尝试根据过去 30 天的 comment_date 和 create_user_id 获取记录。因此,对于 user_id 'BOB' 它不应该返回任何记录,因为有 2/13 和 2/14 的记录(在 comment_date 的 30 天内)。 “STEVE”、“JOHN”和“KEN”也是如此。如何编写 user_id 'TOM'(案例 2)、'KEN'(案例 3)和 'ROSS'(案例 4)的查询?谢谢

comments_sk case    comments         create_user_id   comment_date
120 1 user_comment-1 JOHN 2/16/2017
121 1 user_comment-2 BOB 2/14/2017
122 1 user_comment-3 BOB 1/13/2017
123 2 user_comment-1 BOB 2/13/2017
124 2 user_comment-2 STEVE 2/13/2017
125 2 user_comment-3 TOM 1/13/2017
126 3 user_comment-1 JOHN 2/12/2017
127 3 user_comment-2 JOHN 1/12/2017
128 3 user_comment-3 KEN 1/11/2017
129 4 user_comment-1 KEN 2/14/2017
130 4 user_comment-2 ROSS 1/7/2017

最佳答案

 SELECT * 
FROM
Your_Table
WHERE
Comment_date >= DATEADD(day,-30, GETDATE())
and Create_user_id in ('KEN','TOM','ROSS')
and Comments = ''

关于mysql - 根据日期获取记录(最近30天),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291759/

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