Sybase数据库的计数条件为大于和小于



我在sybase数据库中使用以下查询,我需要数据来显示where count(Field1>=2和Field1<=5(Select * FROM Table1 WHERE Field1 IN( SELECT Field1 FROM Table1 GROUP BY Field1 HAVING COUNT(Field1) >= 2 ORDER BY Field1我如何实现这个

您基本上已经完成了:

Select *
FROM Table1
WHERE Field1 IN (SELECT Field1
FROM Table1
GROUP BY Field1
HAVING COUNT(Field1) BETWEEN 2 AND 5
)
ORDER BY Field1;

然而,我建议使用窗口功能:

select t1.*
from (select t1.*, count(*) over (partition by field1) as cnt
from table1 t1
) t1
where t1.cnt between 2 and 5;

相关内容

  • 没有找到相关文章

最新更新