qq_35439212
qq_35439212
2016-12-10 08:10
采纳率: 36.4%
浏览 3.0k

将两条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
    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即可

    点赞 评论

相关推荐