我想查一个表里所有的字段,条件是:去掉重复的标题,并且只取10行。

解决方案 »

  1.   

    select top 10 * from table
    一个表的标题不可能重复,您直接查。
      

  2.   

    SELECT DISTINCT TOP 10  * FROM TABLENAME
      

  3.   

    select distinct top 10 * from employee 
      

  4.   

    with cte as (select *,rn=row_number()over(partition by 标题 order by getdate()))select top 10 * from cte where rn=1
      

  5.   


    with cte as (select *,rn=row_number()over(partition by 标题 order by getdate()))select top 10 * from cte where rn=1
      

  6.   

    select top 10 * from table where 标题 in(select distinct 标题 from table )
    不知道这个适不适合?
      

  7.   

    不是标题吧,应该是列,不重复的数据。
    取前10吧,那应该按什么排序呢!
    因为使用distinct top 10 * ,后面必须有order by 
    --这里暂为按id排序
    SELECT DISTINCT TOP 10  * FROM TABLENAME order by id asc
      

  8.   

    是列,不重复的数据。
    取前10位
    使用distinct top 10 * ,后面必须有order by
    with cte as (select *,rn=row_number()over(partition by 标题 order by getdate()))select top 10 * from cte where rn=1