使用group by和order by的SQL查询

时间:2022-07-27 22:51:40

Want to achieve the following:

想要实现以下目标:

select col1 from table1 where col1 in

(set rowcount 100
select col2a from table2
order by col2b desc) 

group by (col1) having count(col1) > 1

It is throwing error. Please suggest any methods to achieve this.

这是投掷错误。请建议任何方法来实现这一目标。

1 个解决方案

#1


2  

For SQL Server, you can use top:

对于SQL Server,您可以使用top:

select  col1
from    table1
where   col1 in
        (
        select  top 100 col2a
        from    table2
        order by
                col2b desc
        )
group by
        col1
having  count(*) > 1

#1


2  

For SQL Server, you can use top:

对于SQL Server,您可以使用top:

select  col1
from    table1
where   col1 in
        (
        select  top 100 col2a
        from    table2
        order by
                col2b desc
        )
group by
        col1
having  count(*) > 1