1

请我需要将这两个相似的查询合并为一个查询

1.

SELECT avg(size) 
FROM (
    SELECT  size,addr,sha1 
    FROM data WHERE id >= (abs(random()) % (SELECT max(id) FROM data)) LIMIT 8000
);

2.

SELECT sum(size2 * cnt), sum(cnt)  
FROM (
    SELECT size as size2, sha1, COUNT (*) as cnt 
    FROM 
        (
        SELECT size,addr,sha1 
        FROM data 
        WHERE 
            id >= (abs(random()) % (SELECT max(id) FROM data)) LIMIT 8000
        ) 
    GROUP BY sha1, size 
    HAVING count(*)>=2
    );

我会尝试喜欢这个,但它可能不正确。

SELECT sum(size2 * cnt), sum(cnt),  avg(sizeavg) 
FROM 
    (
    SELECT sizeavg, size as size2, sha1, COUNT (*) as cnt 
    FROM 
        (
        SELECT size, size as sizeavg,addr,sha1 
        FROM data 
        WHERE id >= (abs(random()) % (SELECT max(id) FROM data)) 
        LIMIT 8000
        ) 
    GROUP BY sha1, size 
    HAVING count(*)>=2
);
4

0 回答 0