Return 行,仅当行数大于 10 时
Return rows only if count of them is bigger than 10
我有两个要求:
select count(*) <![CDATA[ > ]]> #{count} from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
select * from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
首先我检查所需记录的数量是否大于我设置的数量。如果是真的,那我去拿记录。是否可以将请求合并为一个,仅当计数更大时才返回行?
一种方法是:
select * from (
select * , count(*) over () cc
from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
) tt
where cc > 10 --[your count limit]
或
select * from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
where (select count(*) from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}) > 10 --[your count limit]
我有两个要求:
select count(*) <![CDATA[ > ]]> #{count} from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
select * from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
首先我检查所需记录的数量是否大于我设置的数量。如果是真的,那我去拿记录。是否可以将请求合并为一个,仅当计数更大时才返回行?
一种方法是:
select * from (
select * , count(*) over () cc
from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
) tt
where cc > 10 --[your count limit]
或
select * from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}
where (select count(*) from bundle where updated_at <![CDATA[ > ]]> #{updatedAt}) > 10 --[your count limit]