SQL Server distinct top count Query

Source: Internet
Author: User

Today, a multi-Table query, grouping, and statistics function is available. However, duplicate data occurs, and then distinct is used to solve the duplicate data. <Br/> but paging is required again. Of course, it is top. However, the stored procedure can also handle paging. Top paging is used here. <Br/> however, an error occurs when top and distinct are used. I used top and distinct before. Remember that top and distinct can be used at the same time. <Br/> finally, I checked it and finally got it done. Haha ~~~~ </P> <p> use the sysobjects table as an example. A simple example is as follows: </P> <p> 1. Remove duplicate data, count count </P> <p> select count (distinct (xtype) from sysobjects </P> <p> 2. First 100 queries, remove duplicate data <br/> select distinct Top 100 xtype from sysobjects </P> <p> same as above <br/> select count (distinct (sysstat )) from sysobjects <br/> select distinct top 10 sysstat from sysobjects <br/> select distinct top (select count (distinct (sysstat) from sysobjects) sysstat from sysobjects <br/>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.