sql - 如何使用 sql 以特定格式排列日期
问题描述
![最小最大日期]
!1 我有一个案例,我需要找到日期 1 的最小值、日期 2 和日期结束的最大值。
预期结果是如果日期 1 日期 2 在连续行中具有相等的值 a 那么日期 1 的最小值、日期 2 的最小值、建设性中断的日期结束的最大值。
如果需要任何澄清,请告诉我。.
我使用的代码:
select distinct DAY, county ,
case when (Date_2> Date_1 )then (region) ) then (region)
when (Date_2= Date_1 ) then min (region) Over (Partition By DAY, county )
else region end as region,
case when (Date_2> Date_1 ) then handoff_date
when (Date_2= Date_1 ) then min (handoff_date) Over (Partition By DAY,county )
end as date2,
case when (Date_2= Date_1 )then min(Date_1) Over (Partition By DAY,county )
when (Date_2> Date_1 )then (Date_1) end as date1
, case when (Date_2= Date_1 )then max(Date_end) Over (Partition By DAY,county )
when (Date_2> Date_1 )then (Date_end) end as dateEnd
from table group by 1,2,3,4,5
解决方案
推荐阅读
- python - 打字功能跨文件吗?
- traefik - Traefik 的 Nomad 高可用性
- node.js - OIDC 回调:axios 调用在 router.get 中不起作用
- r - geom_segment - 平行闪避
- woocommerce-rest-api - 在最新的 woocommerce rest api 上使用自定义搜索查询
- xml - 尽管使用条件,XSLT 节点内容仍显示
- mysql - SELECT 行 COUNT 和另一个行值 MYSQL
- python - 如何在python中使用前缀字段更改AFINN字段
- algorithm - 使用反向替换计算算法的复杂度
- blazor - 将 EditFrom 拆分为多个组件