select min( day_id)
,max( day_id)
,max( day_id)::date-min( day_id)::date
-- ,min( day_id)-interval'(max( day_id)::date-min( day_id)::date)day'
from dw_srm_con_effic_dt
SELECT
MIN(day_id) AS earliest_date,
MAX(day_id) AS latest_date,
DATE_PART('day', MAX(day_id)::date - MIN(day_id)::date) AS date_difference
FROM dw_srm_con_effic_dt;
这个数据库不熟
只能给个建议:
一个SQL写不出就两个SQL,两个搞不定就存储过程