我有这样的疑问:
select *
from(
select record_id, hood_id, city_id, TotalDays
from (
select *,
row_number() over(partition by record_id order by end_date desc) rn,
sum(date_diff('day', start_date, end_date)) over(partition by record_id) as TotalDays
from ads
where del_col = false
)
where rn = 1
union
select record_id, hood_id, city_id, TotalDays
from (
select *,
row_number() over(partition by record_id order by end_of_life desc) rn,
sum(date_diff('day', start_date, end_of_life)) over(partition by record_id) as TotalDays
from ads
where del_col = true
)
where rn = 1)
where record_id = 146 and TotalDays <= 60 and TotalDays >= 0
group by record_id, hood_id, city_id, TotalDays
并且输出其:
| 记录标识|发动机罩_id|城市标识|总天数|
| - ------| - ------| - ------| - ------|
| 一百四十六|三个|十二|三十|
| 一百四十六|三个|十二|十个|
我想要这个输出:
| 记录标识|发动机罩_id|城市标识|总天数|
| - ------| - ------| - ------| - ------|
| 一百四十六|三个|十二|四十|
有人有解决这个问题好办法吗?
1条答案
按热度按时间0ve6wy6x1#
您只需使用
SUM
函数添加TotalDays。