Home > database >  Hive several positions of scene graph, solving?
Hive several positions of scene graph, solving?

Time:09-20

If can start during 20180901, end time, 20180905, converted into 20180901201090, 2201090, 3201090, 4201090 5 array,
By that time no function transformation, the great god answers,

CodePudding user response:

SELECT
T1. Brand, t1. TotalDays - IFNULL (t2) midDays, 0) days
The FROM
(SELECT
T1. Brand,
DATEDIFF (MAX (t1) enddate), MIN (t1. Startdate)) + 1 totalDays
The FROM t_sales t1
GROUP BY t1. Brand) t1
LEFT the JOIN (
The SELECT t.b rand, MIN (t.m idDays) midDays FROM
(SELECT
T1. Brand,
(CASE WHEN t1. Enddate & lt; T2. Startdate AND t1. Id & lt;> T2. Id THEN DATEDIFF (t2) startdate, t1, enddate) - 1 the ELSE 0 end) midDays
The FROM t_sales t1 JOIN t_sales t2 ON t1. Brand=t2. Brand
) t WHERE t.m idDays!=0 GROUP BY t.b rand
) t2 ON t1. Brand=t2. Brand