两张表数据如下:
test_date: test2_date
想获取每天所在周的周日
单表查询时
select
date_add(statis_date,1-dayofweek(statis_date))
from test_date
where statis_date>=‘2020-05-10’;
得到如下结果:
两表union all 查询时:
select
tmp.statis_date as sunday
from (
select
date_add(statis_date,1-dayofweek(statis_date)) as statis_date
from test_date
where statis_date>=‘2020-05-10’
union all
select
date_add(statis_date,1-dayofweek(statis_date)) as statis_date
from test2_date
where statis_date>=‘2020-05-10’
)tmp
group by tmp.statis_date;
得到如下奇怪的结果:
若修改成一下sql 则显示正常:
select
tmp.statis_date as sunday
from (
select
date_add(statis_date,-dayofweek(statis_date)) as statis_date
from test_date
where statis_date>=‘2020-05-10’
union all
select
date_add(statis_date,-dayofweek(statis_date)) as statis_date
from test2_date
where statis_date>=‘2020-05-10’
)tmp
group by tmp.statis_date;
万能的CSDNers,有谁碰到过这个问题?怎么解决的呀?欢迎水贴