示例,我有一个包含三列的记录集:
ID,星期,计数
我想要的只是平均数> 1的ID数据。 10.然后,在该示例数据中,将选择id = 1的数据。
感谢。
答案 0 :(得分:0)
SELECT id FROM YourTable GROUP BY id HAVING AVG(count) > 10
答案 1 :(得分:0)
SELECT *
FROM YourTable
WHERE id IN (SELECT id FROM YourTable GROUP BY id HAVING AVG(count) > 10)
或者,如果您正在使用访问数据库(其中IN因任何原因而出现可怕的性能),您可以使用:
SELECT t2.*
FROM (SELECT id FROM YourTable GROUP BY id HAVING AVG(count) > 10) AS t1
INNER JOIN YourTable AS t2 ON t1.id = t2.id
答案 2 :(得分:0)
在大多数数据库中,您也可以使用窗口函数执行此操作:
select t.*
from (select t.*, avg(count) over (partition by id) as avgcount
from t
) t
where avgcount > 10