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
解决方案 »
- 使用聚合函数的sql语句一定要as 新列名me ?
- sql server 中跨数据库拷贝数据的问题
- 希望利用存储过程动态创建表,有人能实现吗
- 又是树型结构, 该如何写?
- 求一Sql语句,有力出力啊,解决立马结分。
- 请教
- 高分求救!!!!!在线急等!!!
- 在修改一个空值记录的时候的情况!
- 在sqlserver6.5中建完表后怎么修改表中的"datatype"和"nulls"字段?
- 我在SQL SERVER 桌面版中设置了数据库自动完全备份,可几天下来还是没任何数据被备份,是何原因??
- 能否在查询分析器中使用语句查询出结果集的显示集中直接修改数据、oracle是可以的sql可以吗?
- 服务不能启动啊????急!!!!
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)
直接用top 3 uid的话不是没排序么? 怎么解决
33 3
17 2
21 1 以上是下面的结果
Select top 3 uid,Count(*) As total from total_u Group By uid Order by total DESC
如何只显示uid又按记录多少来排序?
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