SQL Server distinct top count 查询
2010-09-30 14:43
555 查看
今天做一个多表查询、分组、统计的功能,分组没有问题。不过出现重复的数据,然后用distinct解决重复数据。 但是又要分页,当然是top了。不过存储过程也可以搞定分页的,这里用top分页。 但是用了top、distinct就出现错误了。以前用过top、distinct,记得top、distinct是可以同时使用的。 最后查了下,终于搞定了。呵呵~~~~ 用sysobjects表做示例,简单的演示下: 1、去掉重复的数据,统计count数量 select count(distinct(xtype)) from sysobjects 2、查询前100条,并且去掉重复数据 select distinct top 100 xtype from sysobjects 同上 select count(distinct(sysstat)) from sysobjects select distinct top 10 sysstat from sysobjects select distinct top (select count(distinct(sysstat)) from sysobjects) sysstat from sysobjects
相关文章推荐
- SQL Server distinct top count 查询
- SQL Server Top Clause 分页查询 Paging
- SQL Server select count(distinct *)
- SQL Server Top Clause 分页查询 Paging
- 【SQL优化】使用子查询可提升 COUNT DISTINCT
- 查询所有订单的最新信息的SQL语句的写法 DISTINCT配合count和group by一起完成
- 通过转成SQL来进行查询,解决hql不能在distinct,group by结果集上使用count的问题
- sql 2000 server 重复数据查询
- SQLserver Top
- SQL Server: Top 10 Secrets of a SQL Server Expert
- 在SQL-server2005中如何对运行慢的查询进行分析?
- SQL查询案例:取得分组 TOP-N
- SQL Server SQL查询用时 精确到毫秒
- SQL Server T-SQL高级查询
- Sqlserver SET NOCOUNT ON不返回受影响行数
- MS SQL server 2005中查询某张表从30-40条数据,但主键ID不是连续的
- sql中Distinct&Count的用法
- SQL Server T-SQL高级查询
- MS SQL Server查询优化方法
- 在SQL-SERVER2000中对同一个数据库多张表进行查询时怎样避免笛卡儿乘积???