如何查询一个表格的数据并对其总条件进行汇总,不要一个总数的显示,要同时显示所有记录和总条数。

解决方案 »

  1.   

    没办法 只能用两条sql 
    union all合并下
      

  2.   

    select id,num from a
    union all
    select 'total',sum(sum) from a
      

  3.   

    select id,num from a
    union all
    select total,sum(sum) from a
      

  4.   

    SELECT
    qsj_user.email,
    qsj_user.telephone,
    qsj_user.regdate,
    qsj_user_profile.avatar,
    qsj_user_profile.nickname,
    qsj_user_profile.realname,
    qsj_user.uid
    FROM qsj_user
    LEFT JOIN qsj_user_profile 
    ON qsj_user.uid = qsj_user_profile.uid
    WHERE qsj_user.role = 1
    UNION
    SELECT COUNT(*) FROM qsj_user报错。
    [Err] 1222 - The used SELECT statements have a different number of columnsUNION ALL 我也用过了。