select max(r_date)
from r_table
where r_type ='Ground'
结果->2020年1月10日
select c_id
from c_table
where
c_date betweem [max("r_date") -7 days] and [max(r_date)]
也就是说,c_date应该在“第三次”和“第十次”之间进行过滤。
我的尝试:
WITH
max
AS (SELECT MAX(r_date) AS max_r_date FROM r_table)
select c_id
from c_table
where
c_date between (SELECT max_r_date FROM max) and (select max-7 from ??) --unable to complete
发布于 2020-11-19 04:13:27
你可以试试下面的-
WITH cte_max AS (SELECT MAX(r_date) AS max_r_date FROM r_table where r_type ='Ground')
select c_id
from c_table join cte_max on
c_date>=dateadd('day',-7,max_r_date) and c_date<=max_r_date
https://stackoverflow.com/questions/64905140
复制相似问题