SELECT top 6 [total_u].[uid], total=count([total_u].[uid]),[userinfo].[username],[userinfo].[prov], [userinfo].[photo], [userinfo].[coin] 
FROM [total_u], [userinfo] 
where [total_u].[uid] 
not in(Select top 3 uid from total_u Group By uid Order by total DESC) --这里,uid是一个字段,而选择出来的是两个字段
And [total_u].[uid]=[userinfo].[userid] --这里要加上and
group by [total_u].[uid],[userinfo].[username],[userinfo].[prov],[userinfo].[photo],[userinfo].[coin] 
order by total DESC

解决方案 »

  1.   

    SELECT top 6 [total_u].[uid], total=count([total_u].[uid]),[userinfo].[username],[userinfo].[prov], [userinfo].[photo], [userinfo].[coin] 
    FROM [total_u], [userinfo] 
    where [total_u].[uid] 
    not in(Select top 3 uid from total_u Group By uid Order by total DESC) and  [total_u].[uid]=[userinfo].[userid] 
    group by [total_u].[uid],[userinfo].[username],[userinfo].[prov],[userinfo].[photo],[userinfo].[coin] 
    order by total DESC少了個AND
    并且好像用WHERE NOT IN (只能是一個字段)where [total_u].[uid] 
    not in(Select top 3 uid from total_u Group By uid Order by total DESC)
      

  2.   

    Select top 3 uid,Count(*) As total from total_u Group By uid Order by total DESCuid的顺序是靠count uid一样的记录的多少来排序的。uid值一样的记录有很多。
    直接用top 3 uid的话不是没排序么? 怎么解决
      

  3.   

    uid    total
    33      3
    17      2
    21      1 以上是下面的结果
    Select top 3 uid,Count(*) As total from total_u Group By uid Order by total DESC
    如何只显示uid又按记录多少来排序?
      

  4.   

    不好意思,没看清这个。那这句话改为Select UID from (Select top 3 uid,Count(*) As total from total_u Group By uid Order by total DESC) A
      

  5.   

    完整的语句为
    SELECT top 6 [total_u].[uid], total=count([total_u].[uid]),[userinfo].[username],[userinfo].[prov], [userinfo].[photo], [userinfo].[coin] 
    FROM [total_u], [userinfo] 
    where [total_u].[uid] 
    not in(Select UID from (Select top 3 uid,Count(*) As total from total_u Group By uid Order by total DESC) A) 
    And [total_u].[uid]=[userinfo].[userid] 
    group by [total_u].[uid],[userinfo].[username],[userinfo].[prov],[userinfo].[photo],[userinfo].[coin] 
    order by total DESC