qq_35439212 2016-12-10 08:10 采纳率: 0%
浏览 3482
已采纳

将两条sql语句合并成一条

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即可

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?