汇总多个选择并加入

汇总多个选择并加入

我有以下查询:

select b.giorno , b.totali, b.unici, a.duplicati, round((a.duplicati/b.totali)*100) as percentuale
from
(
    select
        count(count) as duplicati,
        c.day as day
    from
        (
        select
            count(ip) as count,
            date(date) as day,
            ip
        from
            vas_updates
        group by
            ip
        having
            count > 1
        ) as c
    group by day
) as a
left join
(
    select
        count(id_update) as totali,
        count(distinct ip) as unici,
        date(date) as giorno
    from
        vas_updates
    group by
        date(date)
) as b on
    giorno = b.giorno AND
    giorno = day group by giorno


我如何获得总和b.totali,b.unici,a.duplicati和percentuale个性的最后一行?

最佳答案

尝试这个,

SELECT  b.giorno ,
    SUM(b.totali)  AS totali,
    SUM(b.unici) AS unici ,
    SUM(a.duplicati) AS duplicati ,
    ROUND(SUM(( a.duplicati / b.totali ) * 100)) AS percentuale
 FROM    ( SELECT    COUNT(count) AS duplicati ,
                c.day AS day
      FROM      ( SELECT    COUNT(ip) AS count ,
                            date(date) AS day ,
                            ip
                  FROM      vas_updates
                  GROUP BY  ip
                  HAVING    count > 1
                ) AS c
      GROUP BY  day
    ) AS a
    LEFT JOIN ( SELECT  COUNT(id_update) AS totali ,
                        COUNT(DISTINCT ip) AS unici ,
                        date(date) AS giorno
                FROM    vas_updates
                GROUP BY date(date)
              ) AS b ON giorno = b.giorno
                        AND giorno = day
GROUP BY giorno

关于mysql - 汇总多个选择并加入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35180800/

10-11 20:50