select date_format(time,'%Y-%m-%d') as title, count(*) as num from meter where 1=1和select count(*) as imm_num from user u inner join meter m on u.id=m.userId and date_format(u.time,'%Y-%m-%d')=date_format(m.time,'%Y-%m-%d')能合并吗 求大神指点
1条回答 默认 最新
- HarleyZhuge 2016-12-10 08:46关注
你这种情况属于列集合并,实现如下:
SELECT a.title,a.num,b.imm_num FROM
(select date_format(time,'%Y-%m-%d') as title, count(*) as num from meter where 1=1)a,
(select count(*) as imm_num from user u inner join meter m on u.id=m.userId and date_format(u.time,'%Y-%m-%d')=date_format(m.time,'%Y-%m-%d'))b
若是列集字段一样,涉及到记录集合并
只需在两个SELECT中加UNION ALL即可本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报