mysql

random_xy 发布于 2017/11/30 19:52
阅读 106
收藏 0

select 
IFNULL(SUM(AGENT_SCORE),0) sum,
DATE_FORMAT(CREATOR_TIME,'%Y-%m-%d') as CREATOR_TIMEE
from m_share  where  WX_CODE='1000025'
GROUP BY CREATOR_TIMEE 
ORDER BY CREATOR_TIMEE DESC    

select 
IFNULL(SUM(AGENT_SCORE2),0) sum2,
DATE_FORMAT(CREATOR_TIME,'%Y-%m-%d') as CREATOR_TIMEE
from m_share  where  WX_CODE2='1000025'
GROUP BY CREATOR_TIMEE 
ORDER BY CREATOR_TIMEE DESC

select 
IFNULL(SUM(AGENT_SCORE3),0) sum3,
DATE_FORMAT(CREATOR_TIME,'%Y-%m-%d') as CREATOR_TIMEE
from m_share  where  WX_CODE3='1000025'
GROUP BY CREATOR_TIMEE 
ORDER BY CREATOR_TIMEE DESC

三个SQL分别的查询结果见图,现在我想把这三个张表合在一起,比如2017-11-22第一个SQL是35第二个是1第三个为null就不管,那么新的2017-11-22就是36

加载中
0
DeMoNHaDeS
DeMoNHaDeS

union, group by, sum()

0
仁江
仁江

select 
IFNULL(SUM(AGENT_SCORE2),0) sum2,
DATE_FORMAT(CREATOR_TIME,'%Y-%m-%d') as CREATOR_TIMEE
from m_share  where  WX_CODE2='1000025' OR WX_CODE2='1000025' OR WX_CODE3='1000025'
GROUP BY CREATOR_TIMEE 
ORDER BY CREATOR_TIMEE DESC

是这样的意思吗

返回顶部
顶部