select * from
(select DATE_FORMAT(m1, '%Y-%m') as day3 from ( select ('2020-01-23 00:00:00' - INTERVAL DAYOFMONTH('2020-01-23 00:00:00')-1 DAY) +INTERVAL m MONTH as m1 from ( select @rownum:=@rownum+1 as m from (select 1 union select 2 union select 3 union select 4) t1, (select 1 union select 2 union select 3 union select 4) t2, (select 1 union select 2 union select 3 union select 4) t3, (select @rownum:=-1) t0 ) d1 ) d2 where m1<='2020-12-01 00:00:00' order by m1) as datemonths3
left join (select DATE_FORMAT(m1, '%Y-%m') as day1 from ( select ('2020-01-23 00:00:00' - INTERVAL DAYOFMONTH('2020-01-23 00:00:00')-1 DAY) +INTERVAL m MONTH as m1 from ( select @rownum:=@rownum+1 as m from (select 1 union select 2 union select 3 union select 4) t1, (select 1 union select 2 union select 3 union select 4) t2, (select 1 union select 2 union select 3 union select 4) t3, (select @rownum:=-1) t0 ) d1 ) d2 where m1<='2020-12-01 00:00:00' order by m1) as datemonths2 on datemonths2.day1 = datemonths3.day3
1
mm163 2020-11-16 19:18:01 +08:00 1
union
|
3
GroupF OP 再加上条件应该能行,那我就是在表连接以及用函数的时候他们连接,成为新表时候的顺序是怎么
举个小例子 select * from ((select '2020' as b,'20211' as a ) union (select '2021' as b,'20211' ) ) as av group by av.a |
4
GroupF OP 仅针对这个例子,我用 having 还是能满足大概
#分组,a 只能出现一次,但是可能 b 没数据,选有数据的分 select * from ((select '2020' as b,'20221' as a ) union (select '2021' as b,'20221' ) ) as av group by av.a having (b > 0 or b=0) |
5
GroupF OP pps,占用大家公共资源了,用相同语句生成的临时表,就不可以 join
|